microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/ios/iOSDebugModeManager.ts
90lines · 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 | | |
0d77292aJiglioNero4 years ago | 24 | public async 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. | |
0d77292aJiglioNero4 years ago | 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 | ); | |
de32cf1edigeff10 years ago | 51 | } |
| 52 | | |
0d77292aJiglioNero4 years ago | 53 | public async getAppRemoteDebuggingSetting( |
34472878RedMickey5 years ago | 54 | configuration?: string, |
| 55 | productName?: string, | |
| 56 | ): Promise<boolean> { | |
0d77292aJiglioNero4 years ago | 57 | const plistFile = await this.findPListFileWithRetry(configuration, productName); |
| 58 | try { | |
34472878RedMickey5 years ago | 59 | // Attempt to read from the file, but if the property is not defined then return the empty string |
0d77292aJiglioNero4 years ago | 60 | const [executorClassName, remoteDebugEnabled] = await Promise.all([ |
34472878RedMickey5 years ago | 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 | ), | |
0d77292aJiglioNero4 years ago | 69 | ]); |
| 70 | return ( | |
| 71 | executorClassName === IOSDebugModeManager.WEBSOCKET_EXECUTOR_NAME && | |
| 72 | remoteDebugEnabled === "true" | |
| 73 | ); | |
| 74 | } catch (e) { | |
| 75 | return false; | |
| 76 | } | |
1ed272e1digeff10 years ago | 77 | } |
| 78 | | |
0d77292aJiglioNero4 years ago | 79 | protected async tryOneAttemptToFindPListFile( |
34472878RedMickey5 years ago | 80 | configuration?: string, |
| 81 | productName?: string, | |
| 82 | ): Promise<string> { | |
0d77292aJiglioNero4 years ago | 83 | try { |
| 84 | return await this.simulatorPlist.findPlistFile(configuration, productName); | |
| 85 | } catch (reason) { | |
09f6024fHeniker4 years ago | 86 | this.logger.debug(`Failed one attempt to find plist file: ${String(reason)}`); |
5c8365a6Artem Egorov8 years ago | 87 | return ""; |
0d77292aJiglioNero4 years ago | 88 | } |
dbe130e4Jimmy Thomson10 years ago | 89 | } |
a9d96b7cdigeff10 years ago | 90 | } |