microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
cf6dd6b9348f1c8adb045db2bfda5432796bfe77

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

82lines · 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";
d7d405aeYuri Skorokhodov7 years ago10import * as nls from "vscode-nls";
11const localize = nls.loadMessageBundle();
a9d96b7cdigeff10 years ago12
1ed272e1digeff10 years ago13export class IOSDebugModeManager {
dbe130e4Jimmy Thomson10 years ago14public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago15private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
278d8e56Vladimir Kotikov8 years ago16private static REMOTE_DEBUGGING_SETTING_NAME = ":RCTDevMenu:isDebuggingRemotely";
de32cf1edigeff10 years ago17private static MAX_RETRIES = 5;
18private static DELAY_UNTIL_RETRY = 2000;
0a68f8dbArtem Egorov8 years ago19private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
de32cf1edigeff10 years ago20
a9d96b7cdigeff10 years ago21private projectRoot: string;
1ed272e1digeff10 years ago22private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago23
a949e43fRuslan Bikkinin7 years ago24constructor(projectRoot: string, scheme?: string) {
a9d96b7cdigeff10 years ago25this.projectRoot = projectRoot;
a949e43fRuslan Bikkinin7 years ago26this.simulatorPlist = new SimulatorPlist(this.projectRoot, scheme);
a9d96b7cdigeff10 years ago27}
28
db6fd42aRuslan Bikkinin7 years ago29public setSimulatorRemoteDebuggingSetting(enable: boolean, configuration?: string, productName?: string): Q.Promise<void> {
de32cf1edigeff10 years ago30const plistBuddy = new PlistBuddy();
31
32// Find the plistFile with the configuration setting
33// There is a race here between us checking for the plist file, and the application starting up.
db6fd42aRuslan Bikkinin7 years ago34return this.findPListFile(configuration, productName)
de32cf1edigeff10 years ago35.then((plistFile: string) => {
36// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
37// This is approximately equivalent to clicking the "Debug in Chrome" button
278d8e56Vladimir Kotikov8 years ago38
39return (enable
dbe130e4Jimmy Thomson10 years ago40? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME)
278d8e56Vladimir Kotikov8 years ago41: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME))
42.then(() => plistBuddy.setPlistBooleanProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME, enable));
de32cf1edigeff10 years ago43});
44}
45
db6fd42aRuslan Bikkinin7 years ago46public getSimulatorRemoteDebuggingSetting(configuration?: string, productName?: string): Q.Promise<boolean> {
47return this.findPListFile(configuration, productName)
278d8e56Vladimir Kotikov8 years ago48.then((plistFile: string) => {
49// Attempt to read from the file, but if the property is not defined then return the empty string
50return Q.all([
51new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME),
52new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME),
53])
54.spread((executorClassName: string, remoteDebugEnabled: string) => {
55return executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME
56&& remoteDebugEnabled === "true";
57})
58.catch(() => false);
59});
1ed272e1digeff10 years ago60}
61
db6fd42aRuslan Bikkinin7 years ago62public findPListFile(configuration?: string, productName?: string): Q.Promise<string> {
1ed272e1digeff10 years ago63const pu = new PromiseUtil();
d7d405aeYuri Skorokhodov7 years ago64const failureString = localize("UnableToFindPlistFileToConfigureDebugging", "Unable to find plist file to configure debugging");
1ed272e1digeff10 years ago65
1d00ededdigeff10 years ago66return pu.retryAsync(
67() =>
db6fd42aRuslan Bikkinin7 years ago68this.tryOneAttemptToFindPListFile(configuration, productName), // Operation to retry until successful
1ed272e1digeff10 years ago69(file: string) =>
5c8365a6Artem Egorov8 years ago70file !== "", // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago71IOSDebugModeManager.MAX_RETRIES,
72IOSDebugModeManager.DELAY_UNTIL_RETRY,
de32cf1edigeff10 years ago73failureString); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago74}
dbe130e4Jimmy Thomson10 years ago75
db6fd42aRuslan Bikkinin7 years ago76private tryOneAttemptToFindPListFile(configuration?: string, productName?: string): Q.Promise<string> {
77return this.simulatorPlist.findPlistFile(configuration, productName).catch(reason => {
0a68f8dbArtem Egorov8 years ago78this.logger.debug(`Failed one attempt to find plist file: ${reason}`);
5c8365a6Artem Egorov8 years ago79return "";
5edb6e49Digeff10 years ago80});
dbe130e4Jimmy Thomson10 years ago81}
a9d96b7cdigeff10 years ago82}