microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a9d96b7caa3e169c5e71d976ff9afef9f4c727a9

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/ios/iOSDebugModeManager.ts

38lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as Q from "q";
5
6import {Log} from "../../common/log";
7import {PromiseUtil} from "../../common/node/promise";
8import {PlistBuddy} from "./plistBuddy";
9import {SimulatorPlist} from "./simulatorPlist";
10
11export class iOSDebugModeManager {
12 private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
13 private projectRoot: string;
14
15 constructor(projectRoot: string) {
16 this.projectRoot = projectRoot;
17 }
18
19 public setSimulatorJSDebuggingModeSetting(enable: boolean): Q.Promise<void> {
20 const plistBuddy = new PlistBuddy();
21 const simulatorPlist = new SimulatorPlist(this.projectRoot);
22 const pu = new PromiseUtil();
23
24 const actionText = enable ? "enable" : "disable";
25
26 // Find the plistFile with the configuration setting
27 // There is a race here between us checking for the plist file, and the application starting up.
28 return pu.retryAsync(() => simulatorPlist.findPlistFile().catch((): string => null),
29 (file: string) => file !== null, 5, 2000, `Unable to find plist file to ${actionText} debugging`)
30 .then((plistFile: string) => {
31 // Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
32 // This is approximately equivalent to clicking the "Debug in Chrome" button
33 return enable
34 ? plistBuddy.setPlistProperty(plistFile, iOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, "RCTWebSocketExecutor")
35 : plistBuddy.deletePlistProperty(plistFile, iOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME);
36 });
37 }
38}
39