microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/macos/defaultsHelper.ts
32lines · modeblame
1c2424f4RedMickey5 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 | | |
| 4 | import { Node } from "../../common/node/node"; | |
| 5 | import { ChildProcess } from "../../common/node/childProcess"; | |
| 6 | | |
| 7 | export class DefaultsHelper { | |
| 8 | private readonly DEV_MENU_SETTINGS = "RCTDevMenu"; | |
| 9 | | |
| 10 | private nodeChildProcess: ChildProcess; | |
| 11 | | |
| 12 | constructor() { | |
| 13 | this.nodeChildProcess = new Node.ChildProcess(); | |
| 14 | } | |
| 15 | | |
0d77292aJiglioNero4 years ago | 16 | public async setPlistBooleanProperty( |
1c2424f4RedMickey5 years ago | 17 | plistFile: string, |
| 18 | property: string, | |
| 19 | value: boolean, | |
| 20 | ): Promise<void> { | |
| 21 | // Attempt to set the value, and if it fails due to the key not existing attempt to create the key | |
0d77292aJiglioNero4 years ago | 22 | await this.invokeDefaultsCommand( |
1c2424f4RedMickey5 years ago | 23 | `write ${plistFile} ${this.DEV_MENU_SETTINGS} -dict-add ${property} -bool ${value}`, |
0d77292aJiglioNero4 years ago | 24 | ); |
1c2424f4RedMickey5 years ago | 25 | } |
| 26 | | |
0d77292aJiglioNero4 years ago | 27 | private async invokeDefaultsCommand(command: string): Promise<string> { |
| 28 | const res = await this.nodeChildProcess.exec(`defaults ${command}`); | |
| 29 | const outcome = await res.outcome; | |
| 30 | return outcome.toString().trim(); | |
1c2424f4RedMickey5 years ago | 31 | } |
| 32 | } |