microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
8152571adb22d7628c545490a38bc85153249841

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

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