microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.14.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

84lines · 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;
764655c9Yuri Skorokhodov6 years ago22private iosProjectRoot: string;
1ed272e1digeff10 years ago23private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago24
764655c9Yuri Skorokhodov6 years ago25constructor(iosProjectRoot: string, projectRoot: string, scheme?: string) {
a9d96b7cdigeff10 years ago26this.projectRoot = projectRoot;
764655c9Yuri Skorokhodov6 years ago27this.iosProjectRoot = iosProjectRoot;
28this.simulatorPlist = new SimulatorPlist(this.iosProjectRoot, this.projectRoot, scheme);
a9d96b7cdigeff10 years ago29}
30
db6fd42aRuslan Bikkinin7 years ago31public setSimulatorRemoteDebuggingSetting(enable: boolean, configuration?: string, productName?: string): Q.Promise<void> {
de32cf1edigeff10 years ago32const plistBuddy = new PlistBuddy();
33
34// Find the plistFile with the configuration setting
35// There is a race here between us checking for the plist file, and the application starting up.
db6fd42aRuslan Bikkinin7 years ago36return this.findPListFile(configuration, productName)
de32cf1edigeff10 years ago37.then((plistFile: string) => {
38// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
39// This is approximately equivalent to clicking the "Debug in Chrome" button
278d8e56Vladimir Kotikov8 years ago40
41return (enable
dbe130e4Jimmy Thomson10 years ago42? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME)
278d8e56Vladimir Kotikov8 years ago43: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME))
44.then(() => plistBuddy.setPlistBooleanProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME, enable));
de32cf1edigeff10 years ago45});
46}
47
db6fd42aRuslan Bikkinin7 years ago48public getSimulatorRemoteDebuggingSetting(configuration?: string, productName?: string): Q.Promise<boolean> {
49return this.findPListFile(configuration, productName)
278d8e56Vladimir Kotikov8 years ago50.then((plistFile: string) => {
51// Attempt to read from the file, but if the property is not defined then return the empty string
52return Q.all([
53new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME),
54new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME),
55])
56.spread((executorClassName: string, remoteDebugEnabled: string) => {
57return executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME
58&& remoteDebugEnabled === "true";
59})
60.catch(() => false);
61});
1ed272e1digeff10 years ago62}
63
db6fd42aRuslan Bikkinin7 years ago64public findPListFile(configuration?: string, productName?: string): Q.Promise<string> {
1ed272e1digeff10 years ago65const pu = new PromiseUtil();
d7d405aeYuri Skorokhodov7 years ago66const failureString = localize("UnableToFindPlistFileToConfigureDebugging", "Unable to find plist file to configure debugging");
1ed272e1digeff10 years ago67
1d00ededdigeff10 years ago68return pu.retryAsync(
69() =>
db6fd42aRuslan Bikkinin7 years ago70this.tryOneAttemptToFindPListFile(configuration, productName), // Operation to retry until successful
1ed272e1digeff10 years ago71(file: string) =>
5c8365a6Artem Egorov8 years ago72file !== "", // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago73IOSDebugModeManager.MAX_RETRIES,
74IOSDebugModeManager.DELAY_UNTIL_RETRY,
de32cf1edigeff10 years ago75failureString); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago76}
dbe130e4Jimmy Thomson10 years ago77
db6fd42aRuslan Bikkinin7 years ago78private tryOneAttemptToFindPListFile(configuration?: string, productName?: string): Q.Promise<string> {
79return this.simulatorPlist.findPlistFile(configuration, productName).catch(reason => {
0a68f8dbArtem Egorov8 years ago80this.logger.debug(`Failed one attempt to find plist file: ${reason}`);
5c8365a6Artem Egorov8 years ago81return "";
5edb6e49Digeff10 years ago82});
dbe130e4Jimmy Thomson10 years ago83}
a9d96b7cdigeff10 years ago84}