microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/common/ios/iOSDebugModeManager.ts
38lines · 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 | |
| 4 | import * as Q from "q"; |
| 5 | |
| 6 | import {Log} from "../../common/log"; |
| 7 | import {PromiseUtil} from "../../common/node/promise"; |
| 8 | import {PlistBuddy} from "./plistBuddy"; |
| 9 | import {SimulatorPlist} from "./simulatorPlist"; |
| 10 | |
| 11 | export class iOSDebugModeManager { |
| 12 | private static EXECUTOR_CLASS_SETTING_NAME = ":RCTDevMenu:executorClass"; |
| 13 | private projectRoot: string; |
| 14 | |
| 15 | constructor(projectRoot: string) { |
| 16 | this.projectRoot = projectRoot; |
| 17 | } |
| 18 | |
| 19 | public setSimulatorJSDebuggingModeSetting(enable: boolean): Q.Promise<void> { |
| 20 | const plistBuddy = new PlistBuddy(); |
| 21 | const simulatorPlist = new SimulatorPlist(this.projectRoot); |
| 22 | const pu = new PromiseUtil(); |
| 23 | |
| 24 | const actionText = enable ? "enable" : "disable"; |
| 25 | |
| 26 | // Find the plistFile with the configuration setting |
| 27 | // There is a race here between us checking for the plist file, and the application starting up. |
| 28 | return pu.retryAsync(() => simulatorPlist.findPlistFile().catch((): string => null), |
| 29 | (file: string) => file !== null, 5, 2000, `Unable to find plist file to ${actionText} debugging`) |
| 30 | .then((plistFile: string) => { |
| 31 | // Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode |
| 32 | // This is approximately equivalent to clicking the "Debug in Chrome" button |
| 33 | return enable |
| 34 | ? plistBuddy.setPlistProperty(plistFile, iOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME, "RCTWebSocketExecutor") |
| 35 | : plistBuddy.deletePlistProperty(plistFile, iOSDebugModeManager.EXECUTOR_CLASS_SETTING_NAME); |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 | |