microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
43e6ccc3781e2fec953ee0059638ffa0e5d403ab

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/iOSDebugModeManager.ts

90lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { ApplePlatformDebugModeManager } from "../applePlatformDebugModeManager";
5import { PlistBuddy } from "./plistBuddy";
6import { SimulatorPlist } from "./simulatorPlist";
7
8export class IOSDebugModeManager extends ApplePlatformDebugModeManager {
9 public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor";
10 private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass";
11
12 private simulatorPlist: SimulatorPlist;
13
14 constructor(iosProjectRoot: string, projectRoot: string, scheme?: string) {
15 super(iosProjectRoot, projectRoot);
16 this.projectRoot = projectRoot;
17 this.simulatorPlist = new SimulatorPlist(
18 this.platformProjectRoot,
19 this.projectRoot,
20 scheme,
21 );
22 }
23
24 public async setAppRemoteDebuggingSetting(
25 enable: boolean,
26 configuration?: string,
27 productName?: string,
28 ): Promise<void> {
29 const 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.
33 const 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
36 await (enable
37 ? plistBuddy.setPlistProperty(
38 plistFile,
39 IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
40 IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME,
41 )
42 : plistBuddy.deletePlistProperty(
43 plistFile,
44 IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
45 ));
46 await plistBuddy.setPlistBooleanProperty(
47 plistFile,
48 IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
49 enable,
50 );
51 }
52
53 public async getAppRemoteDebuggingSetting(
54 configuration?: string,
55 productName?: string,
56 ): Promise<boolean> {
57 const plistFile = await this.findPListFileWithRetry(configuration, productName);
58 try {
59 // Attempt to read from the file, but if the property is not defined then return the empty string
60 const [executorClassName, remoteDebugEnabled] = await Promise.all([
61 new PlistBuddy().readPlistProperty(
62 plistFile,
63 IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME,
64 ),
65 new PlistBuddy().readPlistProperty(
66 plistFile,
67 IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
68 ),
69 ]);
70 return (
71 executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME &&
72 remoteDebugEnabled === "true"
73 );
74 } catch (e) {
75 return false;
76 }
77 }
78
79 protected async tryOneAttemptToFindPListFile(
80 configuration?: string,
81 productName?: string,
82 ): Promise<string> {
83 try {
84 return await this.simulatorPlist.findPlistFile(configuration, productName);
85 } catch (reason) {
86 this.logger.debug(`Failed one attempt to find plist file: ${reason}`);
87 return "";
88 }
89 }
90}
91