microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
30d12ab8ec0f57ab20a3dc05bbb13707e040d75e

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/iOSDebugModeManager.ts

64lines · 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 {PromiseUtil} from "../../common/node/promise";
7import {PlistBuddy} from "./plistBuddy";
8import {SimulatorPlist} from "./simulatorPlist";
9
1ed272e1digeff10 years ago10export class IOSDebugModeManager {
dbe130e4Jimmy Thomson10 years ago11public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago12private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
de32cf1edigeff10 years ago13private static MAX_RETRIES = 5;
14private static DELAY_UNTIL_RETRY = 2000;
15
a9d96b7cdigeff10 years ago16private projectRoot: string;
1ed272e1digeff10 years ago17private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago18
19constructor(projectRoot: string) {
20this.projectRoot = projectRoot;
1ed272e1digeff10 years ago21this.simulatorPlist = new SimulatorPlist(this.projectRoot);
a9d96b7cdigeff10 years ago22}
23
de32cf1edigeff10 years ago24public setSimulatorJSDebuggingModeSetting(enable: boolean): Q.Promise<void> {
25const plistBuddy = new PlistBuddy();
26
27// Find the plistFile with the configuration setting
28// There is a race here between us checking for the plist file, and the application starting up.
dbe130e4Jimmy Thomson10 years ago29return this.findPListFile()
de32cf1edigeff10 years ago30.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
33return enable
dbe130e4Jimmy Thomson10 years ago34? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME)
de32cf1edigeff10 years ago35: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME);
36});
37}
38
dbe130e4Jimmy Thomson10 years ago39public getSimulatorJSDebuggingModeSetting(): Q.Promise<string> {
40return this.findPListFile().then((plistFile: string) => {
41// Attempt to read from the file, but if the property is not defined then return the empty string
42return new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME)
43.catch(() => "");
44});
1ed272e1digeff10 years ago45}
46
dbe130e4Jimmy Thomson10 years ago47public findPListFile(): Q.Promise<string> {
1ed272e1digeff10 years ago48const pu = new PromiseUtil();
dbe130e4Jimmy Thomson10 years ago49const failureString = `Unable to find plist file to configure debugging`;
1ed272e1digeff10 years ago50
1d00ededdigeff10 years ago51return pu.retryAsync(
52() =>
80002087Joshua Skelton10 years ago53this.tryOneAttemptToFindPListFile(), // Operation to retry until successful
1ed272e1digeff10 years ago54(file: string) =>
80002087Joshua Skelton10 years ago55file !== null, // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago56IOSDebugModeManager.MAX_RETRIES,
57IOSDebugModeManager.DELAY_UNTIL_RETRY,
de32cf1edigeff10 years ago58failureString); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago59}
dbe130e4Jimmy Thomson10 years ago60
61private tryOneAttemptToFindPListFile() {
62return this.simulatorPlist.findPlistFile().catch((): string => null);
63}
a9d96b7cdigeff10 years ago64}