microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.0.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

81lines · 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 semver from "semver";
5import * as path from "path";
de838bbfJiglioNero6 years ago6import {GeneralMobilePlatform} from "../generalMobilePlatform";
dd90a856Artem Egorov7 years ago7import {MobilePlatformDeps} from "../generalMobilePlatform";
259c018fYuri Skorokhodov5 years ago8import {IWindowsRunOptions, PlatformType} from "../launchArgs";
dd90a856Artem Egorov7 years ago9import {TelemetryHelper} from "../../common/telemetryHelper";
10import {CommandExecutor} from "../../common/commandExecutor";
11import {WindowsPlatform} from "./windowsPlatform";
d7d405aeYuri Skorokhodov7 years ago12import * as nls from "vscode-nls";
2d8af448Yuri Skorokhodov6 years ago13nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
d7d405aeYuri Skorokhodov7 years ago14const localize = nls.loadMessageBundle();
dd90a856Artem Egorov7 years ago15
16/**
17* WPF specific platform implementation for debugging RN applications.
18*/
19export class WpfPlatform extends WindowsPlatform {
20private static WPF_SUPPORTED = "0.55.0";
21constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
22super(runOptions, platformDeps);
23}
24
ce5e88eeYuri Skorokhodov5 years ago25public runApp(enableDebug: boolean = true): Promise<void> {
ba953e9fRedMickey6 years ago26let extProps = {
dd90a856Artem Egorov7 years ago27platform: {
259c018fYuri Skorokhodov5 years ago28value: PlatformType.WPF,
dd90a856Artem Egorov7 years ago29isPii: false,
30},
31};
32
7fa90b3bRedMickey6 years ago33extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeVersion, "reactNativeVersion", extProps);
34extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps);
ba953e9fRedMickey6 years ago35
dd90a856Artem Egorov7 years ago36return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => {
de838bbfJiglioNero6 years ago37const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile);
dd90a856Artem Egorov7 years ago38
39if (enableDebug) {
db6fd42aRuslan Bikkinin7 years ago40this.runArguments.push("--proxy");
dd90a856Artem Egorov7 years ago41}
42
7fa90b3bRedMickey6 years ago43if (!semver.gt(this.runOptions.reactNativeVersions.reactNativeVersion, WpfPlatform.WPF_SUPPORTED)) {
44throw new Error(localize("DebuggingWPFPlatformIsNotSupportedForThisRNWinVersion", "Debugging WPF platform is not supported for this react-native-windows version({0})", this.runOptions.reactNativeVersions.reactNativeVersion));
ba953e9fRedMickey6 years ago45}
dd90a856Artem Egorov7 years ago46
7fa90b3bRedMickey6 years ago47if (!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 ago48this.runArguments.push("--no-packager");
49}
dd90a856Artem Egorov7 years ago50
ba953e9fRedMickey6 years ago51const exec = new CommandExecutor(this.projectPath, this.logger);
ce5e88eeYuri Skorokhodov5 years ago52return new Promise((resolve, reject) => {
ba953e9fRedMickey6 years ago53const 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(() => {
57const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
58let resolved = false;
59let output = "";
60runWpfSpawn.stdout.on("data", (data: Buffer) => {
61output += data.toString();
62if (!resolved && output.indexOf("Starting the app") > -1) {
63resolved = true;
ce5e88eeYuri Skorokhodov5 years ago64resolve();
ba953e9fRedMickey6 years ago65}
66});
dd90a856Artem Egorov7 years ago67
ba953e9fRedMickey6 years ago68runWpfSpawn.stderr.on("data", (error: Buffer) => {
69if (error.toString().trim()) {
70reject(error.toString());
71}
72});
dd90a856Artem Egorov7 years ago73
ba953e9fRedMickey6 years ago74runWpfSpawn.outcome.then(() => {
ce5e88eeYuri Skorokhodov5 years ago75reject(); // If WPF process ended then app run fault
ba953e9fRedMickey6 years ago76});
dd90a856Artem Egorov7 years ago77});
ba953e9fRedMickey6 years ago78});
dd90a856Artem Egorov7 years ago79});
80}
81}