microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
legacy

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

82lines · 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 * as Q from "q";
5import * as semver from "semver";
6import * as path from "path";
7
8import {GeneralMobilePlatform} from "../generalMobilePlatform";
9import {MobilePlatformDeps} from "../generalMobilePlatform";
10import {IWindowsRunOptions} from "../launchArgs";
11import {TelemetryHelper} from "../../common/telemetryHelper";
12import {CommandExecutor} from "../../common/commandExecutor";
13import {WindowsPlatform} from "./windowsPlatform";
14import * as nls from "vscode-nls";
15const localize = nls.loadMessageBundle();
16
17/**
18 * WPF specific platform implementation for debugging RN applications.
19 */
20export class WpfPlatform extends WindowsPlatform {
21 private static WPF_SUPPORTED = "0.55.0";
22 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
23 super(runOptions, platformDeps);
24 }
25
26 public runApp(enableDebug: boolean = true): Q.Promise<void> {
27 let extProps = {
28 platform: {
29 value: "wpf",
30 isPii: false,
31 },
32 };
33
34 extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeVersion, "reactNativeVersion", extProps);
35 extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps);
36
37 return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => {
38 const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile);
39
40 if (enableDebug) {
41 this.runArguments.push("--proxy");
42 }
43
44 if (!semver.gt(this.runOptions.reactNativeVersions.reactNativeVersion, WpfPlatform.WPF_SUPPORTED)) {
45 throw new Error(localize("DebuggingWPFPlatformIsNotSupportedForThisRNWinVersion", "Debugging WPF platform is not supported for this react-native-windows version({0})", this.runOptions.reactNativeVersions.reactNativeVersion));
46 }
47
48 if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, WpfPlatform.NO_PACKAGER_VERSION)) {
49 this.runArguments.push("--no-packager");
50 }
51
52 const exec = new CommandExecutor(this.projectPath, this.logger);
53 return Q.Promise((resolve, reject) => {
54 const appName = this.projectPath.split(path.sep).pop();
55 // Killing another instances of the app which were run earlier
56 return exec.execute(`cmd /C Taskkill /IM ${appName}.exe /F`)
57 .finally(() => {
58 const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
59 let resolved = false;
60 let output = "";
61 runWpfSpawn.stdout.on("data", (data: Buffer) => {
62 output += data.toString();
63 if (!resolved && output.indexOf("Starting the app") > -1) {
64 resolved = true;
65 resolve(void 0);
66 }
67 });
68
69 runWpfSpawn.stderr.on("data", (error: Buffer) => {
70 if (error.toString().trim()) {
71 reject(error.toString());
72 }
73 });
74
75 runWpfSpawn.outcome.then(() => {
76 reject(void 0); // If WPF process ended then app run fault
77 });
78 });
79 });
80 });
81 }
82}
83