microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.7.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/macos/defaultsHelper.ts

32lines · 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
4import { Node } from "../../common/node/node";
5import { ChildProcess } from "../../common/node/childProcess";
6
7export 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 async 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 await this.invokeDefaultsCommand(
23 `write ${plistFile} ${this.DEV_MENU_SETTINGS} -dict-add ${property} -bool ${value}`,
24 );
25 }
26
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();
31 }
32}
33