microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

83lines · 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
0a68f8dbArtem Egorov8 years ago4import {OutputChannelLogger} from "../log/OutputChannelLogger";
a9d96b7cdigeff10 years ago5import {PromiseUtil} from "../../common/node/promise";
6import {PlistBuddy} from "./plistBuddy";
7import {SimulatorPlist} from "./simulatorPlist";
d7d405aeYuri Skorokhodov7 years ago8import * as nls from "vscode-nls";
2d8af448Yuri Skorokhodov6 years ago9nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
d7d405aeYuri Skorokhodov7 years ago10const localize = nls.loadMessageBundle();
a9d96b7cdigeff10 years ago11
1ed272e1digeff10 years ago12export class IOSDebugModeManager {
dbe130e4Jimmy Thomson10 years ago13public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago14private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
278d8e56Vladimir Kotikov8 years ago15private static REMOTE_DEBUGGING_SETTING_NAME = ":RCTDevMenu:isDebuggingRemotely";
de32cf1edigeff10 years ago16private static MAX_RETRIES = 5;
17private static DELAY_UNTIL_RETRY = 2000;
0a68f8dbArtem Egorov8 years ago18private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
de32cf1edigeff10 years ago19
a9d96b7cdigeff10 years ago20private projectRoot: string;
764655c9Yuri Skorokhodov6 years ago21private iosProjectRoot: string;
1ed272e1digeff10 years ago22private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago23
764655c9Yuri Skorokhodov6 years ago24constructor(iosProjectRoot: string, projectRoot: string, scheme?: string) {
a9d96b7cdigeff10 years ago25this.projectRoot = projectRoot;
764655c9Yuri Skorokhodov6 years ago26this.iosProjectRoot = iosProjectRoot;
27this.simulatorPlist = new SimulatorPlist(this.iosProjectRoot, this.projectRoot, scheme);
a9d96b7cdigeff10 years ago28}
29
ce5e88eeYuri Skorokhodov5 years ago30public setSimulatorRemoteDebuggingSetting(enable: boolean, configuration?: string, productName?: string): Promise<void> {
de32cf1edigeff10 years ago31const plistBuddy = new PlistBuddy();
32
33// Find the plistFile with the configuration setting
34// There is a race here between us checking for the plist file, and the application starting up.
db6fd42aRuslan Bikkinin7 years ago35return this.findPListFile(configuration, productName)
de32cf1edigeff10 years ago36.then((plistFile: string) => {
37// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
38// This is approximately equivalent to clicking the "Debug in Chrome" button
278d8e56Vladimir Kotikov8 years ago39
40return (enable
dbe130e4Jimmy Thomson10 years ago41? plistBuddy.setPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME)
278d8e56Vladimir Kotikov8 years ago42: plistBuddy.deletePlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME))
43.then(() => plistBuddy.setPlistBooleanProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME, enable));
de32cf1edigeff10 years ago44});
45}
46
ce5e88eeYuri Skorokhodov5 years ago47public getSimulatorRemoteDebuggingSetting(configuration?: string, productName?: string): Promise<boolean> {
db6fd42aRuslan Bikkinin7 years ago48return this.findPListFile(configuration, productName)
278d8e56Vladimir Kotikov8 years ago49.then((plistFile: string) => {
50// Attempt to read from the file, but if the property is not defined then return the empty string
ce5e88eeYuri Skorokhodov5 years ago51return Promise.all([
278d8e56Vladimir Kotikov8 years ago52new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME),
53new PlistBuddy().readPlistProperty(plistFile, IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME),
54])
ce5e88eeYuri Skorokhodov5 years ago55.then(([executorClassName, remoteDebugEnabled]) => {
278d8e56Vladimir Kotikov8 years ago56return executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME
57&& remoteDebugEnabled === "true";
58})
59.catch(() => false);
60});
1ed272e1digeff10 years ago61}
62
ce5e88eeYuri Skorokhodov5 years ago63public findPListFile(configuration?: string, productName?: string): Promise<string> {
1ed272e1digeff10 years ago64const pu = new PromiseUtil();
d7d405aeYuri Skorokhodov7 years ago65const failureString = localize("UnableToFindPlistFileToConfigureDebugging", "Unable to find plist file to configure debugging");
1ed272e1digeff10 years ago66
1d00ededdigeff10 years ago67return pu.retryAsync(
68() =>
db6fd42aRuslan Bikkinin7 years ago69this.tryOneAttemptToFindPListFile(configuration, productName), // Operation to retry until successful
1ed272e1digeff10 years ago70(file: string) =>
5c8365a6Artem Egorov8 years ago71file !== "", // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago72IOSDebugModeManager.MAX_RETRIES,
73IOSDebugModeManager.DELAY_UNTIL_RETRY,
de32cf1edigeff10 years ago74failureString); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago75}
dbe130e4Jimmy Thomson10 years ago76
ce5e88eeYuri Skorokhodov5 years ago77private tryOneAttemptToFindPListFile(configuration?: string, productName?: string): Promise<string> {
db6fd42aRuslan Bikkinin7 years ago78return this.simulatorPlist.findPlistFile(configuration, productName).catch(reason => {
0a68f8dbArtem Egorov8 years ago79this.logger.debug(`Failed one attempt to find plist file: ${reason}`);
5c8365a6Artem Egorov8 years ago80return "";
5edb6e49Digeff10 years ago81});
dbe130e4Jimmy Thomson10 years ago82}
a9d96b7cdigeff10 years ago83}