microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1ed272e1484a2ca3dcbce4fdac2dfe8845692866

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/iOSDebugModeManager.ts

57lines · modeblame

a9d96b7cdigeff10 years ago1// 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
1ed272e1digeff10 years ago11export class IOSDebugModeManager {
a9d96b7cdigeff10 years ago12private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
13private projectRoot: string;
1ed272e1digeff10 years ago14private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago15
16constructor(projectRoot: string) {
17this.projectRoot = projectRoot;
1ed272e1digeff10 years ago18this.simulatorPlist = new SimulatorPlist(this.projectRoot);
a9d96b7cdigeff10 years ago19}
20
1ed272e1digeff10 years ago21private tryOneAttemptToFindPListFile() {
22return this.simulatorPlist.findPlistFile().catch((): string => null);
23}
24
25private static MAX_RETRIES = 5;
26private static DELAY_UNTIL_RETRY = 2000;
a9d96b7cdigeff10 years ago27
1ed272e1digeff10 years ago28private findPListFile(enable: boolean): Q.Promise<string> {
29const pu = new PromiseUtil();
a9d96b7cdigeff10 years ago30const actionText = enable ? "enable" : "disable";
31
1ed272e1digeff10 years ago32const failureString = `Unable to find plist file to ${actionText} debugging`;
33
34return pu.retryAsync(() =>
35this.tryOneAttemptToFindPListFile(), // Operation to retry until succesful
36(file: string) =>
37file !== null, // Condition to check if the operation was succesful, and this logic is done
38IOSDebugModeManager.MAX_RETRIES,
39IOSDebugModeManager.DELAY_UNTIL_RETRY,
40failureString) // Error to show in case all retries fail
41}
42
43public setSimulatorJSDebuggingModeSetting(enable: boolean): Q.Promise<void> {
44const plistBuddy = new PlistBuddy();
45
a9d96b7cdigeff10 years ago46// Find the plistFile with the configuration setting
47// There is a race here between us checking for the plist file, and the application starting up.
1ed272e1digeff10 years ago48return this.findPListFile(enable)
a9d96b7cdigeff10 years ago49.then((plistFile: string) => {
50// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
51// This is approximately equivalent to clicking the "Debug in Chrome" button
52return enable
1ed272e1digeff10 years ago53? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, "RCTWebSocketExecutor")
54: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME);
a9d96b7cdigeff10 years ago55});
56}
57}