microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
58882bb6b3dda8f9ee5cf6fad0f03021b3cb44a3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

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