microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
test-microbuild1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

90lines · 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
1c2424f4RedMickey5 years ago4import { ApplePlatformDebugModeManager } from "../applePlatformDebugModeManager";
34472878RedMickey5 years ago5import { PlistBuddy } from "./plistBuddy";
6import { SimulatorPlist } from "./simulatorPlist";
a9d96b7cdigeff10 years ago7
1c2424f4RedMickey5 years ago8export class IOSDebugModeManager extends ApplePlatformDebugModeManager {
dbe130e4Jimmy Thomson10 years ago9public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
a9d96b7cdigeff10 years ago10private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
de32cf1edigeff10 years ago11
1ed272e1digeff10 years ago12private simulatorPlist: SimulatorPlist;
a9d96b7cdigeff10 years ago13
764655c9Yuri Skorokhodov6 years ago14constructor(iosProjectRoot: string, projectRoot: string, scheme?: string) {
1c2424f4RedMickey5 years ago15super(iosProjectRoot, projectRoot);
a9d96b7cdigeff10 years ago16this.projectRoot = projectRoot;
1c2424f4RedMickey5 years ago17this.simulatorPlist = new SimulatorPlist(
18this.platformProjectRoot,
19this.projectRoot,
20scheme,
21);
a9d96b7cdigeff10 years ago22}
23
0d77292aJiglioNero4 years ago24public async setAppRemoteDebuggingSetting(
34472878RedMickey5 years ago25enable: boolean,
26configuration?: string,
27productName?: string,
28): Promise<void> {
de32cf1edigeff10 years ago29const plistBuddy = new PlistBuddy();
30
31// Find the plistFile with the configuration setting
32// There is a race here between us checking for the plist file, and the application starting up.
0d77292aJiglioNero4 years ago33const plistFile = await this.findPListFileWithRetry(configuration, productName);
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
36await (enable
37? plistBuddy.setPlistProperty(
38plistFile,
39IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
40IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME,
41)
42: plistBuddy.deletePlistProperty(
43plistFile,
44IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
45));
46await plistBuddy.setPlistBooleanProperty(
47plistFile,
48IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
49enable,
50);
de32cf1edigeff10 years ago51}
52
0d77292aJiglioNero4 years ago53public async getAppRemoteDebuggingSetting(
34472878RedMickey5 years ago54configuration?: string,
55productName?: string,
56): Promise<boolean> {
0d77292aJiglioNero4 years ago57const plistFile = await this.findPListFileWithRetry(configuration, productName);
58try {
34472878RedMickey5 years ago59// Attempt to read from the file, but if the property is not defined then return the empty string
0d77292aJiglioNero4 years ago60const [executorClassName, remoteDebugEnabled] = await Promise.all([
34472878RedMickey5 years ago61new PlistBuddy().readPlistProperty(
62plistFile,
63IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
64),
65new PlistBuddy().readPlistProperty(
66plistFile,
67IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
68),
0d77292aJiglioNero4 years ago69]);
70return (
71executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME &&
72remoteDebugEnabled === "true"
73);
74} catch (e) {
75return false;
76}
1ed272e1digeff10 years ago77}
78
0d77292aJiglioNero4 years ago79protected async tryOneAttemptToFindPListFile(
34472878RedMickey5 years ago80configuration?: string,
81productName?: string,
82): Promise<string> {
0d77292aJiglioNero4 years ago83try {
84return await this.simulatorPlist.findPlistFile(configuration, productName);
85} catch (reason) {
09f6024fHeniker4 years ago86this.logger.debug(`Failed one attempt to find plist file: ${String(reason)}`);
5c8365a6Artem Egorov8 years ago87return "";
0d77292aJiglioNero4 years ago88}
dbe130e4Jimmy Thomson10 years ago89}
a9d96b7cdigeff10 years ago90}