microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.10.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

82lines · modeblame

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