microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1174ee3dd094e08cacea7cb751e143257d5641fe

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

80lines · 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
0a68f8dbArtem Egorov8 years ago6import {OutputChannelLogger} from "../log/OutputChannelLogger";
a9d96b7cdigeff10 years ago7import {PromiseUtil} from "../../common/node/promise";
8import {PlistBuddy} from "./plistBuddy";
9import {SimulatorPlist} from "./simulatorPlist";
10
1ed272e1digeff10 years ago11export class IOSDebugModeManager {
dbe130e4Jimmy Thomson10 years ago12public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago13private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
278d8e56Vladimir Kotikov8 years ago14private static REMOTE_DEBUGGING_SETTING_NAME = ":RCTDevMenu:isDebuggingRemotely";
de32cf1edigeff10 years ago15private static MAX_RETRIES = 5;
16private static DELAY_UNTIL_RETRY = 2000;
0a68f8dbArtem Egorov8 years ago17private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
de32cf1edigeff10 years ago18
a9d96b7cdigeff10 years ago19private projectRoot: string;
1ed272e1digeff10 years ago20private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago21
22constructor(projectRoot: string) {
23this.projectRoot = projectRoot;
1ed272e1digeff10 years ago24this.simulatorPlist = new SimulatorPlist(this.projectRoot);
a9d96b7cdigeff10 years ago25}
26
278d8e56Vladimir Kotikov8 years ago27public setSimulatorRemoteDebuggingSetting(enable: boolean): Q.Promise<void> {
de32cf1edigeff10 years ago28const plistBuddy = new PlistBuddy();
29
30// Find the plistFile with the configuration setting
31// There is a race here between us checking for the plist file, and the application starting up.
dbe130e4Jimmy Thomson10 years ago32return this.findPListFile()
de32cf1edigeff10 years ago33.then((plistFile: string) => {
34// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
35// This is approximately equivalent to clicking the "Debug in Chrome" button
278d8e56Vladimir Kotikov8 years ago36
37return (enable
dbe130e4Jimmy Thomson10 years ago38? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME)
278d8e56Vladimir Kotikov8 years ago39: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME))
40.then(() => plistBuddy.setPlistBooleanProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME, enable));
de32cf1edigeff10 years ago41});
42}
43
278d8e56Vladimir Kotikov8 years ago44public getSimulatorRemoteDebuggingSetting(): Q.Promise<boolean> {
45return this.findPListFile()
46.then((plistFile: string) => {
47// Attempt to read from the file, but if the property is not defined then return the empty string
48return Q.all([
49new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME),
50new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME),
51])
52.spread((executorClassName: string, remoteDebugEnabled: string) => {
53return executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME
54&& remoteDebugEnabled === "true";
55})
56.catch(() => false);
57});
1ed272e1digeff10 years ago58}
59
dbe130e4Jimmy Thomson10 years ago60public findPListFile(): Q.Promise<string> {
1ed272e1digeff10 years ago61const pu = new PromiseUtil();
dbe130e4Jimmy Thomson10 years ago62const failureString = `Unable to find plist file to configure debugging`;
1ed272e1digeff10 years ago63
1d00ededdigeff10 years ago64return pu.retryAsync(
65() =>
80002087Joshua Skelton10 years ago66this.tryOneAttemptToFindPListFile(), // Operation to retry until successful
1ed272e1digeff10 years ago67(file: string) =>
5c8365a6Artem Egorov8 years ago68file !== "", // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago69IOSDebugModeManager.MAX_RETRIES,
70IOSDebugModeManager.DELAY_UNTIL_RETRY,
de32cf1edigeff10 years ago71failureString); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago72}
dbe130e4Jimmy Thomson10 years ago73
5edb6e49Digeff10 years ago74private tryOneAttemptToFindPListFile(): Q.Promise<string> {
75return this.simulatorPlist.findPlistFile().catch(reason => {
0a68f8dbArtem Egorov8 years ago76this.logger.debug(`Failed one attempt to find plist file: ${reason}`);
5c8365a6Artem Egorov8 years ago77return "";
5edb6e49Digeff10 years ago78});
dbe130e4Jimmy Thomson10 years ago79}
a9d96b7cdigeff10 years ago80}