microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
legacy

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

82lines · 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
5f0a4a46JiglioNero6 years ago8import {GeneralMobilePlatform} from "../generalMobilePlatform";
dd90a856Artem Egorov8 years ago9import {MobilePlatformDeps} from "../generalMobilePlatform";
10import {IWindowsRunOptions} from "../launchArgs";
11import {TelemetryHelper} from "../../common/telemetryHelper";
12import {CommandExecutor} from "../../common/commandExecutor";
13import {WindowsPlatform} from "./windowsPlatform";
d7d405aeYuri Skorokhodov7 years ago14import * as nls from "vscode-nls";
15const localize = nls.loadMessageBundle();
dd90a856Artem Egorov8 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> {
ba953e9fRedMickey6 years ago27let extProps = {
dd90a856Artem Egorov8 years ago28platform: {
29value: "wpf",
30isPii: false,
31},
32};
33
7fa90b3bRedMickey6 years ago34extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeVersion, "reactNativeVersion", extProps);
35extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps);
ba953e9fRedMickey6 years ago36
dd90a856Artem Egorov8 years ago37return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => {
5f0a4a46JiglioNero6 years ago38const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile);
dd90a856Artem Egorov8 years ago39
40if (enableDebug) {
db6fd42aRuslan Bikkinin7 years ago41this.runArguments.push("--proxy");
dd90a856Artem Egorov8 years ago42}
43
7fa90b3bRedMickey6 years ago44if (!semver.gt(this.runOptions.reactNativeVersions.reactNativeVersion, WpfPlatform.WPF_SUPPORTED)) {
45throw new Error(localize("DebuggingWPFPlatformIsNotSupportedForThisRNWinVersion", "Debugging WPF platform is not supported for this react-native-windows version({0})", this.runOptions.reactNativeVersions.reactNativeVersion));
ba953e9fRedMickey6 years ago46}
dd90a856Artem Egorov8 years ago47
7fa90b3bRedMickey6 years ago48if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, WpfPlatform.NO_PACKAGER_VERSION)) {
ba953e9fRedMickey6 years ago49this.runArguments.push("--no-packager");
50}
dd90a856Artem Egorov8 years ago51
ba953e9fRedMickey6 years ago52const exec = new CommandExecutor(this.projectPath, this.logger);
53return Q.Promise((resolve, reject) => {
54const appName = this.projectPath.split(path.sep).pop();
55// Killing another instances of the app which were run earlier
56return exec.execute(`cmd /C Taskkill /IM ${appName}.exe /F`)
57.finally(() => {
58const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
59let resolved = false;
60let output = "";
61runWpfSpawn.stdout.on("data", (data: Buffer) => {
62output += data.toString();
63if (!resolved && output.indexOf("Starting the app") > -1) {
64resolved = true;
65resolve(void 0);
66}
67});
dd90a856Artem Egorov8 years ago68
ba953e9fRedMickey6 years ago69runWpfSpawn.stderr.on("data", (error: Buffer) => {
70if (error.toString().trim()) {
71reject(error.toString());
72}
73});
dd90a856Artem Egorov8 years ago74
ba953e9fRedMickey6 years ago75runWpfSpawn.outcome.then(() => {
76reject(void 0); // If WPF process ended then app run fault
77});
dd90a856Artem Egorov8 years ago78});
ba953e9fRedMickey6 years ago79});
dd90a856Artem Egorov8 years ago80});
81}
82}