microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fced706df75baed17e7c94a4b833767cbc0edf9f

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/iOSDebugModeManager.ts

69lines · 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
5edb6e49Digeff10 years ago6import {Log} from "../../common/log/log";
7import {LogLevel} from "../../common/log/logHelper";
a9d96b7cdigeff10 years ago8import {PromiseUtil} from "../../common/node/promise";
9import {PlistBuddy} from "./plistBuddy";
10import {SimulatorPlist} from "./simulatorPlist";
11
1ed272e1digeff10 years ago12export class IOSDebugModeManager {
dbe130e4Jimmy Thomson10 years ago13public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago14private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
de32cf1edigeff10 years ago15private static MAX_RETRIES = 5;
16private static DELAY_UNTIL_RETRY = 2000;
17
a9d96b7cdigeff10 years ago18private projectRoot: string;
1ed272e1digeff10 years ago19private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago20
21constructor(projectRoot: string) {
22this.projectRoot = projectRoot;
1ed272e1digeff10 years ago23this.simulatorPlist = new SimulatorPlist(this.projectRoot);
a9d96b7cdigeff10 years ago24}
25
de32cf1edigeff10 years ago26public setSimulatorJSDebuggingModeSetting(enable: boolean): Q.Promise<void> {
27const plistBuddy = new PlistBuddy();
28
29// Find the plistFile with the configuration setting
30// There is a race here between us checking for the plist file, and the application starting up.
dbe130e4Jimmy Thomson10 years ago31return this.findPListFile()
de32cf1edigeff10 years ago32.then((plistFile: string) => {
33// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
34// This is approximately equivalent to clicking the "Debug in Chrome" button
35return enable
dbe130e4Jimmy Thomson10 years ago36? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME)
de32cf1edigeff10 years ago37: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME);
38});
39}
40
dbe130e4Jimmy Thomson10 years ago41public getSimulatorJSDebuggingModeSetting(): Q.Promise<string> {
42return this.findPListFile().then((plistFile: string) => {
43// Attempt to read from the file, but if the property is not defined then return the empty string
44return new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME)
45.catch(() => "");
46});
1ed272e1digeff10 years ago47}
48
dbe130e4Jimmy Thomson10 years ago49public findPListFile(): Q.Promise<string> {
1ed272e1digeff10 years ago50const pu = new PromiseUtil();
dbe130e4Jimmy Thomson10 years ago51const failureString = `Unable to find plist file to configure debugging`;
1ed272e1digeff10 years ago52
1d00ededdigeff10 years ago53return pu.retryAsync(
54() =>
80002087Joshua Skelton10 years ago55this.tryOneAttemptToFindPListFile(), // Operation to retry until successful
1ed272e1digeff10 years ago56(file: string) =>
80002087Joshua Skelton10 years ago57file !== null, // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago58IOSDebugModeManager.MAX_RETRIES,
59IOSDebugModeManager.DELAY_UNTIL_RETRY,
de32cf1edigeff10 years ago60failureString); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago61}
dbe130e4Jimmy Thomson10 years ago62
5edb6e49Digeff10 years ago63private tryOneAttemptToFindPListFile(): Q.Promise<string> {
64return this.simulatorPlist.findPlistFile().catch(reason => {
65Log.logInternalMessage(LogLevel.Info, `Failed one attempt to find plist file: ${reason}`);
66return null;
67});
dbe130e4Jimmy Thomson10 years ago68}
a9d96b7cdigeff10 years ago69}