microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/wpfPlatform.ts
81lines · modeblame
dd90a856Artem Egorov7 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
| 4 | import * as semver from "semver"; | |
| 5 | import * as path from "path"; | |
de838bbfJiglioNero6 years ago | 6 | import {GeneralMobilePlatform} from "../generalMobilePlatform"; |
dd90a856Artem Egorov7 years ago | 7 | import {MobilePlatformDeps} from "../generalMobilePlatform"; |
259c018fYuri Skorokhodov5 years ago | 8 | import {IWindowsRunOptions, PlatformType} from "../launchArgs"; |
dd90a856Artem Egorov7 years ago | 9 | import {TelemetryHelper} from "../../common/telemetryHelper"; |
| 10 | import {CommandExecutor} from "../../common/commandExecutor"; | |
| 11 | import {WindowsPlatform} from "./windowsPlatform"; | |
d7d405aeYuri Skorokhodov7 years ago | 12 | import * as nls from "vscode-nls"; |
2d8af448Yuri Skorokhodov6 years ago | 13 | nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); |
d7d405aeYuri Skorokhodov7 years ago | 14 | const localize = nls.loadMessageBundle(); |
dd90a856Artem Egorov7 years ago | 15 | |
| 16 | /** | |
| 17 | * WPF specific platform implementation for debugging RN applications. | |
| 18 | */ | |
| 19 | export class WpfPlatform extends WindowsPlatform { | |
| 20 | private static WPF_SUPPORTED = "0.55.0"; | |
| 21 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 22 | super(runOptions, platformDeps); | |
| 23 | } | |
| 24 | | |
ce5e88eeYuri Skorokhodov5 years ago | 25 | public runApp(enableDebug: boolean = true): Promise<void> { |
ba953e9fRedMickey6 years ago | 26 | let extProps = { |
dd90a856Artem Egorov7 years ago | 27 | platform: { |
259c018fYuri Skorokhodov5 years ago | 28 | value: PlatformType.WPF, |
dd90a856Artem Egorov7 years ago | 29 | isPii: false, |
| 30 | }, | |
| 31 | }; | |
| 32 | | |
7fa90b3bRedMickey6 years ago | 33 | extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeVersion, "reactNativeVersion", extProps); |
| 34 | extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps); | |
ba953e9fRedMickey6 years ago | 35 | |
dd90a856Artem Egorov7 years ago | 36 | return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => { |
de838bbfJiglioNero6 years ago | 37 | const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile); |
dd90a856Artem Egorov7 years ago | 38 | |
| 39 | if (enableDebug) { | |
db6fd42aRuslan Bikkinin7 years ago | 40 | this.runArguments.push("--proxy"); |
dd90a856Artem Egorov7 years ago | 41 | } |
| 42 | | |
7fa90b3bRedMickey6 years ago | 43 | if (!semver.gt(this.runOptions.reactNativeVersions.reactNativeVersion, WpfPlatform.WPF_SUPPORTED)) { |
| 44 | throw new Error(localize("DebuggingWPFPlatformIsNotSupportedForThisRNWinVersion", "Debugging WPF platform is not supported for this react-native-windows version({0})", this.runOptions.reactNativeVersions.reactNativeVersion)); | |
ba953e9fRedMickey6 years ago | 45 | } |
dd90a856Artem Egorov7 years ago | 46 | |
7fa90b3bRedMickey6 years ago | 47 | if (!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 ago | 48 | this.runArguments.push("--no-packager"); |
| 49 | } | |
dd90a856Artem Egorov7 years ago | 50 | |
ba953e9fRedMickey6 years ago | 51 | const exec = new CommandExecutor(this.projectPath, this.logger); |
ce5e88eeYuri Skorokhodov5 years ago | 52 | return new Promise((resolve, reject) => { |
ba953e9fRedMickey6 years ago | 53 | const appName = this.projectPath.split(path.sep).pop(); |
| 54 | // Killing another instances of the app which were run earlier | |
| 55 | return exec.execute(`cmd /C Taskkill /IM ${appName}.exe /F`) | |
| 56 | .finally(() => { | |
| 57 | const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env}); | |
| 58 | let resolved = false; | |
| 59 | let output = ""; | |
| 60 | runWpfSpawn.stdout.on("data", (data: Buffer) => { | |
| 61 | output += data.toString(); | |
| 62 | if (!resolved && output.indexOf("Starting the app") > -1) { | |
| 63 | resolved = true; | |
ce5e88eeYuri Skorokhodov5 years ago | 64 | resolve(); |
ba953e9fRedMickey6 years ago | 65 | } |
| 66 | }); | |
dd90a856Artem Egorov7 years ago | 67 | |
ba953e9fRedMickey6 years ago | 68 | runWpfSpawn.stderr.on("data", (error: Buffer) => { |
| 69 | if (error.toString().trim()) { | |
| 70 | reject(error.toString()); | |
| 71 | } | |
| 72 | }); | |
dd90a856Artem Egorov7 years ago | 73 | |
ba953e9fRedMickey6 years ago | 74 | runWpfSpawn.outcome.then(() => { |
ce5e88eeYuri Skorokhodov5 years ago | 75 | reject(); // If WPF process ended then app run fault |
ba953e9fRedMickey6 years ago | 76 | }); |
dd90a856Artem Egorov7 years ago | 77 | }); |
ba953e9fRedMickey6 years ago | 78 | }); |
dd90a856Artem Egorov7 years ago | 79 | }); |
| 80 | } | |
| 81 | } |