microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

113lines · 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 semver from "semver";
5import * as path from "path";
6import { GeneralMobilePlatform } from "../generalMobilePlatform";
7import { MobilePlatformDeps } from "../generalMobilePlatform";
8import { IWindowsRunOptions, PlatformType } from "../launchArgs";
9import { TelemetryHelper } from "../../common/telemetryHelper";
10import { CommandExecutor } from "../../common/commandExecutor";
11import { WindowsPlatform } from "./windowsPlatform";
12import * as nls from "vscode-nls";
13nls.config({
14 messageFormat: nls.MessageFormat.bundle,
15 bundleFormat: nls.BundleFormat.standalone,
16})();
17const localize = nls.loadMessageBundle();
18
19/**
20 * WPF specific platform implementation for debugging RN applications.
21 */
22export class WpfPlatform extends WindowsPlatform {
23 private static WPF_SUPPORTED = "0.55.0";
24 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
25 super(runOptions, platformDeps);
26 }
27
28 public runApp(enableDebug: boolean = true): Promise<void> {
29 let extProps = {
30 platform: {
31 value: PlatformType.WPF,
32 isPii: false,
33 },
34 };
35
36 extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
37 this.runOptions,
38 this.runOptions.reactNativeVersions,
39 extProps,
40 );
41
42 return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => {
43 const env = GeneralMobilePlatform.getEnvArgument(
44 process.env,
45 this.runOptions.env,
46 this.runOptions.envFile,
47 );
48
49 if (enableDebug) {
50 this.runArguments.push("--proxy");
51 }
52
53 if (
54 !semver.gt(
55 this.runOptions.reactNativeVersions.reactNativeVersion,
56 WpfPlatform.WPF_SUPPORTED,
57 )
58 ) {
59 throw new Error(
60 localize(
61 "DebuggingWPFPlatformIsNotSupportedForThisRNWinVersion",
62 "Debugging WPF platform is not supported for this react-native-windows version({0})",
63 this.runOptions.reactNativeVersions.reactNativeVersion,
64 ),
65 );
66 }
67
68 if (
69 !semver.valid(
70 this.runOptions.reactNativeVersions.reactNativeVersion,
71 ) /*Custom RN implementations should support this flag*/ ||
72 semver.gte(
73 this.runOptions.reactNativeVersions.reactNativeVersion,
74 WpfPlatform.NO_PACKAGER_VERSION,
75 )
76 ) {
77 this.runArguments.push("--no-packager");
78 }
79
80 const exec = new CommandExecutor(this.projectPath, this.logger);
81 return new Promise((resolve, reject) => {
82 const appName = this.projectPath.split(path.sep).pop();
83 // Killing another instances of the app which were run earlier
84 return exec.execute(`cmd /C Taskkill /IM ${appName}.exe /F`).finally(() => {
85 const runWpfSpawn = exec.spawnReactCommand(
86 `run-${this.platformName}`,
87 this.runArguments,
88 { env },
89 );
90 let resolved = false;
91 let output = "";
92 runWpfSpawn.stdout.on("data", (data: Buffer) => {
93 output += data.toString();
94 if (!resolved && output.indexOf("Starting the app") > -1) {
95 resolved = true;
96 resolve();
97 }
98 });
99
100 runWpfSpawn.stderr.on("data", (error: Buffer) => {
101 if (error.toString().trim()) {
102 reject(error.toString());
103 }
104 });
105
106 runWpfSpawn.outcome.then(() => {
107 reject(); // If WPF process ended then app run fault
108 });
109 });
110 });
111 });
112 }
113}