microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.13

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

81lines · 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 {MobilePlatformDeps} from "../generalMobilePlatform";
9import {IWindowsRunOptions} from "../launchArgs";
10import {TelemetryHelper} from "../../common/telemetryHelper";
11import {CommandExecutor} from "../../common/commandExecutor";
12import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper";
13import {WindowsPlatform} from "./windowsPlatform";
14
15/**
16 * WPF specific platform implementation for debugging RN applications.
17 */
18export class WpfPlatform extends WindowsPlatform {
19 private static WPF_SUPPORTED = "0.55.0";
20 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
21 super(runOptions, platformDeps);
22 }
23
24 public runApp(enableDebug: boolean = true): Q.Promise<void> {
25 const extProps = {
26 platform: {
27 value: "wpf",
28 isPii: false,
29 },
30 };
31
32 return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => {
33 const runArguments = this.getRunArgument();
34 const env = this.getEnvArgument();
35
36 if (enableDebug) {
37 runArguments.push("--proxy");
38 }
39
40 return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot)
41 .then(version => {
42 if (!semver.gt(version, WpfPlatform.WPF_SUPPORTED)) {
43 throw new Error(`Debugging WPF platform is not supported for this react-native-windows version(${version})`);
44 }
45
46 if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WpfPlatform.NO_PACKAGER_VERSION)) {
47 runArguments.push("--no-packager");
48 }
49
50 const exec = new CommandExecutor(this.projectPath, this.logger);
51 return Q.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}`, 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(void 0);
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(void 0); // If WPF process ended then app run fault
75 });
76 });
77 });
78 });
79 });
80 }
81}
82