microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
sourcemap-handle-null-sections

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/macos/macOSDebugModeManager.ts

97lines · modeblame

1c2424f4RedMickey5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as path from "path";
5import { homedir } from "os";
6import { ApplePlatformDebugModeManager } from "../applePlatformDebugModeManager";
7import { PlistBuddy } from "../ios/plistBuddy";
8import { FileSystem } from "../../common/node/fileSystem";
9import { PlatformType } from "../launchArgs";
10import { DefaultsHelper } from "./defaultsHelper";
11
12export class MacOSDebugModeManager extends ApplePlatformDebugModeManager {
13protected static REMOTE_DEBUGGING_FLAG_NAME = "isDebuggingRemotely";
14
15private scheme?: string;
16private nodeFileSystem: FileSystem;
17private plistBuddy: PlistBuddy;
18private defaultsHelper: DefaultsHelper;
19
20constructor(
21macosProjectRoot: string,
22projectRoot: string,
23scheme?: string,
24{ nodeFileSystem = new FileSystem(), plistBuddy = undefined } = {},
25) {
26super(macosProjectRoot, projectRoot);
27this.scheme = scheme;
28this.nodeFileSystem = nodeFileSystem;
29this.plistBuddy = plistBuddy || new PlistBuddy();
30this.defaultsHelper = new DefaultsHelper();
31}
32
0d77292aJiglioNero4 years ago33public async setAppRemoteDebuggingSetting(
1c2424f4RedMickey5 years ago34enable: boolean,
35configuration?: string,
36productName?: string,
37): Promise<void> {
38// Find the plistFile with the configuration setting
39// There is a race here between us checking for the plist file, and the application starting up.
0d77292aJiglioNero4 years ago40const plistFile = await this.findPListFileWithRetry(configuration, productName);
41// Set the "isDebuggingRemotely" flag to "true", so on the next startup the application will default into debug mode
42// This is approximately equivalent to clicking the "Debug in Chrome" button
43return await this.defaultsHelper.setPlistBooleanProperty(
44plistFile,
45MacOSDebugModeManager.REMOTE_DEBUGGING_FLAG_NAME,
46enable,
47);
1c2424f4RedMickey5 years ago48}
49
0d77292aJiglioNero4 years ago50public async getAppRemoteDebuggingSetting(
1c2424f4RedMickey5 years ago51configuration?: string,
52productName?: string,
53): Promise<boolean> {
0d77292aJiglioNero4 years ago54const plistFile = await this.findPListFileWithRetry(configuration, productName);
55try {
1c2424f4RedMickey5 years ago56// Attempt to read from the file, but if the property is not defined then return the empty string
0d77292aJiglioNero4 years ago57const remoteDebugEnabled = await this.plistBuddy.readPlistProperty(
58plistFile,
59MacOSDebugModeManager.REMOTE_DEBUGGING_SETTING_NAME,
60);
61return remoteDebugEnabled === "true";
62} catch (e) {
63return false;
64}
1c2424f4RedMickey5 years ago65}
66
0d77292aJiglioNero4 years ago67protected async tryOneAttemptToFindPListFile(
1c2424f4RedMickey5 years ago68configuration?: string,
69productName?: string,
70): Promise<string> {
0d77292aJiglioNero4 years ago71try {
72return await this.findPlistFile(configuration, productName);
73} catch (reason) {
09f6024fHeniker4 years ago74this.logger.debug(`Failed one attempt to find plist file: ${String(reason)}`);
1c2424f4RedMickey5 years ago75return "";
0d77292aJiglioNero4 years ago76}
1c2424f4RedMickey5 years ago77}
78
0d77292aJiglioNero4 years ago79private async findPlistFile(configuration?: string, productName?: string): Promise<string> {
80const bundleId = await this.plistBuddy.getBundleId(
81this.platformProjectRoot,
82this.projectRoot,
83PlatformType.macOS,
84false,
85configuration,
86productName,
87this.scheme,
88); // Find the name of the application
89const plistFilePath = path.join(homedir(), "Library", "Preferences", `${bundleId}.plist`);
90const exist = await this.nodeFileSystem.exists(plistFilePath);
91if (!exist) {
92throw new Error(`Unable to find plist file for ${bundleId}`);
93} else {
94return plistFilePath;
95}
1c2424f4RedMickey5 years ago96}
97}