microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/ios/iOSDebugModeManager.ts
92lines · modeblame
a9d96b7cdigeff10 years ago | 1 | // 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 ago | 4 | import { ApplePlatformDebugModeManager } from "../applePlatformDebugModeManager"; |
34472878RedMickey5 years ago | 5 | import { PlistBuddy } from "./plistBuddy"; |
| 6 | import { SimulatorPlist } from "./simulatorPlist"; | |
a9d96b7cdigeff10 years ago | 7 | |
1c2424f4RedMickey5 years ago | 8 | export class IOSDebugModeManager extends ApplePlatformDebugModeManager { |
dbe130e4Jimmy Thomson10 years ago | 9 | public static WEBSOCKET_EXECUTOR_NAME = "RCTWebSocketExecutor"; |
a9d96b7cdigeff10 years ago | 10 | private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass"; |
de32cf1edigeff10 years ago | 11 | |
1ed272e1digeff10 years ago | 12 | private simulatorPlist: SimulatorPlist; |
a9d96b7cdigeff10 years ago | 13 | |
764655c9Yuri Skorokhodov6 years ago | 14 | constructor(iosProjectRoot: string, projectRoot: string, scheme?: string) { |
1c2424f4RedMickey5 years ago | 15 | super(iosProjectRoot, projectRoot); |
a9d96b7cdigeff10 years ago | 16 | this.projectRoot = projectRoot; |
1c2424f4RedMickey5 years ago | 17 | this.simulatorPlist = new SimulatorPlist( |
| 18 | this.platformProjectRoot, | |
| 19 | this.projectRoot, | |
| 20 | scheme, | |
| 21 | ); | |
a9d96b7cdigeff10 years ago | 22 | } |
| 23 | | |
1c2424f4RedMickey5 years ago | 24 | public setAppRemoteDebuggingSetting( |
34472878RedMickey5 years ago | 25 | enable: boolean, |
| 26 | configuration?: string, | |
| 27 | productName?: string, | |
| 28 | ): Promise<void> { | |
de32cf1edigeff10 years ago | 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. | |
1c2424f4RedMickey5 years ago | 33 | return this.findPListFileWithRetry(configuration, productName).then((plistFile: string) => { |
34472878RedMickey5 years ago | 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 | |
278d8e56Vladimir Kotikov8 years ago | 36 | |
34472878RedMickey5 years ago | 37 | return (enable |
| 38 | ? plistBuddy.setPlistProperty( | |
| 39 | plistFile, | |
| 40 | IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, | |
| 41 | IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME, | |
| 42 | ) | |
| 43 | : plistBuddy.deletePlistProperty( | |
| 44 | plistFile, | |
| 45 | IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, | |
| 46 | ) | |
| 47 | ).then(() => | |
| 48 | plistBuddy.setPlistBooleanProperty( | |
| 49 | plistFile, | |
| 50 | IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME, | |
| 51 | enable, | |
| 52 | ), | |
| 53 | ); | |
| 54 | }); | |
de32cf1edigeff10 years ago | 55 | } |
| 56 | | |
1c2424f4RedMickey5 years ago | 57 | public getAppRemoteDebuggingSetting( |
34472878RedMickey5 years ago | 58 | configuration?: string, |
| 59 | productName?: string, | |
| 60 | ): Promise<boolean> { | |
1c2424f4RedMickey5 years ago | 61 | return this.findPListFileWithRetry(configuration, productName).then((plistFile: string) => { |
34472878RedMickey5 years ago | 62 | // Attempt to read from the file, but if the property is not defined then return the empty string |
| 63 | return Promise.all([ | |
| 64 | new PlistBuddy().readPlistProperty( | |
| 65 | plistFile, | |
| 66 | IOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, | |
| 67 | ), | |
| 68 | new PlistBuddy().readPlistProperty( | |
| 69 | plistFile, | |
| 70 | IOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME, | |
| 71 | ), | |
| 72 | ]) | |
| 73 | .then(([executorClassName, remoteDebugEnabled]) => { | |
| 74 | return ( | |
| 75 | executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME && | |
| 76 | remoteDebugEnabled === "true" | |
| 77 | ); | |
| 78 | }) | |
| 79 | .catch(() => false); | |
| 80 | }); | |
1ed272e1digeff10 years ago | 81 | } |
| 82 | | |
1c2424f4RedMickey5 years ago | 83 | protected tryOneAttemptToFindPListFile( |
34472878RedMickey5 years ago | 84 | configuration?: string, |
| 85 | productName?: string, | |
| 86 | ): Promise<string> { | |
db6fd42aRuslan Bikkinin7 years ago | 87 | return this.simulatorPlist.findPlistFile(configuration, productName).catch(reason => { |
0a68f8dbArtem Egorov8 years ago | 88 | this.logger.debug(`Failed one attempt to find plist file: ${reason}`); |
5c8365a6Artem Egorov8 years ago | 89 | return ""; |
5edb6e49Digeff10 years ago | 90 | }); |
dbe130e4Jimmy Thomson10 years ago | 91 | } |
a9d96b7cdigeff10 years ago | 92 | } |