microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bcb44c4d4e94b00d16fc644eee9a1d64a2ef86b7

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

117lines · 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
34472878RedMickey5 years ago4import { OutputChannelLogger } from "../log/OutputChannelLogger";
5import { PromiseUtil } from "../../common/node/promise";
6import { PlistBuddy } from "./plistBuddy";
7import { SimulatorPlist } from "./simulatorPlist";
d7d405aeYuri Skorokhodov7 years ago8import * as nls from "vscode-nls";
34472878RedMickey5 years ago9nls.config({
10messageFormat: nls.MessageFormat.bundle,
11bundleFormat: nls.BundleFormat.standalone,
12})();
d7d405aeYuri Skorokhodov7 years ago13const localize = nls.loadMessageBundle();
a9d96b7cdigeff10 years ago14
1ed272e1digeff10 years ago15export class IOSDebugModeManager {
dbe130e4Jimmy Thomson10 years ago16public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago17private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
278d8e56Vladimir Kotikov8 years ago18private static REMOTE_DEBUGGING_SETTING_NAME = ":RCTDevMenu:isDebuggingRemotely";
de32cf1edigeff10 years ago19private static MAX_RETRIES = 5;
20private static DELAY_UNTIL_RETRY = 2000;
0a68f8dbArtem Egorov8 years ago21private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
de32cf1edigeff10 years ago22
a9d96b7cdigeff10 years ago23private projectRoot: string;
764655c9Yuri Skorokhodov6 years ago24private iosProjectRoot: string;
1ed272e1digeff10 years ago25private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago26
764655c9Yuri Skorokhodov6 years ago27constructor(iosProjectRoot: string, projectRoot: string, scheme?: string) {
a9d96b7cdigeff10 years ago28this.projectRoot = projectRoot;
764655c9Yuri Skorokhodov6 years ago29this.iosProjectRoot = iosProjectRoot;
30this.simulatorPlist = new SimulatorPlist(this.iosProjectRoot, this.projectRoot, scheme);
a9d96b7cdigeff10 years ago31}
32
34472878RedMickey5 years ago33public setSimulatorRemoteDebuggingSetting(
34enable: boolean,
35configuration?: string,
36productName?: string,
37): Promise<void> {
de32cf1edigeff10 years ago38const plistBuddy = new PlistBuddy();
39
40// Find the plistFile with the configuration setting
41// There is a race here between us checking for the plist file, and the application starting up.
34472878RedMickey5 years ago42return this.findPListFile(configuration, productName).then((plistFile: string) => {
43// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
44// This is approximately equivalent to clicking the "Debug in Chrome" button
278d8e56Vladimir Kotikov8 years ago45
34472878RedMickey5 years ago46return (enable
47? plistBuddy.setPlistProperty(
48plistFile,
49IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
50IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME,
51)
52: plistBuddy.deletePlistProperty(
53plistFile,
54IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
55)
56).then(() =>
57plistBuddy.setPlistBooleanProperty(
58plistFile,
59IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
60enable,
61),
62);
63});
de32cf1edigeff10 years ago64}
65
34472878RedMickey5 years ago66public getSimulatorRemoteDebuggingSetting(
67configuration?: string,
68productName?: string,
69): Promise<boolean> {
70return this.findPListFile(configuration, productName).then((plistFile: string) => {
71// Attempt to read from the file, but if the property is not defined then return the empty string
72return Promise.all([
73new PlistBuddy().readPlistProperty(
74plistFile,
75IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
76),
77new PlistBuddy().readPlistProperty(
78plistFile,
79IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
80),
81])
82.then(([executorClassName, remoteDebugEnabled]) => {
83return (
84executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME &&
85remoteDebugEnabled === "true"
86);
87})
88.catch(() => false);
89});
1ed272e1digeff10 years ago90}
91
ce5e88eeYuri Skorokhodov5 years ago92public findPListFile(configuration?: string, productName?: string): Promise<string> {
1ed272e1digeff10 years ago93const pu = new PromiseUtil();
34472878RedMickey5 years ago94const failureString = localize(
95"UnableToFindPlistFileToConfigureDebugging",
96"Unable to find plist file to configure debugging",
97);
1ed272e1digeff10 years ago98
1d00ededdigeff10 years ago99return pu.retryAsync(
34472878RedMickey5 years ago100() => this.tryOneAttemptToFindPListFile(configuration, productName), // Operation to retry until successful
101(file: string) => file !== "", // Condition to check if the operation was successful, and this logic is done
1ed272e1digeff10 years ago102IOSDebugModeManager.MAX_RETRIES,
103IOSDebugModeManager.DELAY_UNTIL_RETRY,
34472878RedMickey5 years ago104failureString,
105); // Error to show in case all retries fail
a9d96b7cdigeff10 years ago106}
dbe130e4Jimmy Thomson10 years ago107
34472878RedMickey5 years ago108private tryOneAttemptToFindPListFile(
109configuration?: string,
110productName?: string,
111): Promise<string> {
db6fd42aRuslan Bikkinin7 years ago112return this.simulatorPlist.findPlistFile(configuration, productName).catch(reason => {
0a68f8dbArtem Egorov8 years ago113this.logger.debug(`Failed one attempt to find plist file: ${reason}`);
5c8365a6Artem Egorov8 years ago114return "";
5edb6e49Digeff10 years ago115});
dbe130e4Jimmy Thomson10 years ago116}
a9d96b7cdigeff10 years ago117}