microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.7.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

80lines · modeblame

dd90a856Artem Egorov8 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 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 {
19private static WPF_SUPPORTED = "0.55.0";
20constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
21super(runOptions, platformDeps);
22}
23
24public runApp(enableDebug: boolean = true): Q.Promise<void> {
25const extProps = {
26platform: {
27value: "wpf",
28isPii: false,
29},
30};
31
32return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => {
33const env = this.getEnvArgument();
34
35if (enableDebug) {
db6fd42aRuslan Bikkinin7 years ago36this.runArguments.push("--proxy");
dd90a856Artem Egorov8 years ago37}
38
39return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot)
40.then(version => {
41if (!semver.gt(version, WpfPlatform.WPF_SUPPORTED)) {
42throw new Error(`Debugging WPF platform is not supported for this react-native-windows version(${version})`);
43}
44
45if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WpfPlatform.NO_PACKAGER_VERSION)) {
db6fd42aRuslan Bikkinin7 years ago46this.runArguments.push("--no-packager");
dd90a856Artem Egorov8 years ago47}
48
49const exec = new CommandExecutor(this.projectPath, this.logger);
50return Q.Promise((resolve, reject) => {
51const appName = this.projectPath.split(path.sep).pop();
52// Killing another instances of the app which were run earlier
53return exec.execute(`cmd /C Taskkill /IM ${appName}.exe /F`)
54.finally(() => {
db6fd42aRuslan Bikkinin7 years ago55const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
dd90a856Artem Egorov8 years ago56let resolved = false;
57let output = "";
58runWpfSpawn.stdout.on("data", (data: Buffer) => {
59output += data.toString();
60if (!resolved && output.indexOf("Starting the app") > -1) {
61resolved = true;
62resolve(void 0);
63}
64});
65
66runWpfSpawn.stderr.on("data", (error: Buffer) => {
67if (error.toString().trim()) {
68reject(error.toString());
69}
70});
71
72runWpfSpawn.outcome.then(() => {
73reject(void 0); // If WPF process ended then app run fault
74});
75});
76});
77});
78});
79}
80}