microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/macos/defaultsHelper.ts
34lines · 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 { 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 | |
| 16 | public setPlistBooleanProperty( |
| 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 |
| 22 | return this.invokeDefaultsCommand( |
| 23 | `write ${plistFile} ${this.DEV_MENU_SETTINGS} -dict-add ${property} -bool ${value}`, |
| 24 | ).then(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function |
| 25 | } |
| 26 | |
| 27 | private invokeDefaultsCommand(command: string): Promise<string> { |
| 28 | return this.nodeChildProcess.exec(`defaults ${command}`).then(res => |
| 29 | res.outcome.then((result: string) => { |
| 30 | return result.toString().trim(); |
| 31 | }), |
| 32 | ); |
| 33 | } |
| 34 | } |
| 35 | |