microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.14.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/exponent/exponentPlatform.ts

112lines · 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 { ErrorHelper } from "../../common/error/errorHelper";
5import { InternalErrorCode } from "../../common/error/internalErrorCode";
6import { IRunOptions } from "../launchArgs";
7import { GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform";
8import { ExponentHelper } from "./exponentHelper";
9import { TelemetryHelper } from "../../common/telemetryHelper";
10import { QRCodeContentProvider } from "../qrCodeContentProvider";
11
12import * as vscode from "vscode";
13import * as Q from "q";
14import * as XDL from "./xdlInterface";
15import * as url from "url";
16import * as nls from "vscode-nls";
17const localize = nls.loadMessageBundle();
18
19
20export class ExponentPlatform extends GeneralMobilePlatform {
21 private exponentTunnelPath: string | null;
22 private exponentHelper: ExponentHelper;
23 private qrCodeContentProvider: QRCodeContentProvider = new QRCodeContentProvider();
24
25 constructor(runOptions: IRunOptions, platformDeps: MobilePlatformDeps = {}) {
26 super(runOptions, platformDeps);
27 this.exponentHelper = new ExponentHelper(runOptions.workspaceRoot, runOptions.projectRoot);
28 this.exponentTunnelPath = null;
29 }
30
31 public runApp(): Q.Promise<void> {
32 let extProps = {
33 platform: {
34 value: "exponent",
35 isPii: false,
36 },
37 };
38
39 extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeVersion, "reactNativeVersion", extProps);
40
41 return TelemetryHelper.generate("ExponentPlatform.runApp", extProps, () => {
42 return this.exponentHelper.loginToExponent(
43 (message, password) => {
44 return Q.Promise((resolve, reject) => {
45 vscode.window.showInputBox({ placeHolder: message, password: password })
46 .then(login => {
47 resolve(login || "");
48 }, reject);
49 });
50 },
51 (message) => {
52 return Q.Promise((resolve, reject) => {
53 const okButton = { title: "Ok" };
54 const cancelButton = { title: "Cancel", isCloseAffordance: true };
55 vscode.window.showInformationMessage(message, {modal: true}, okButton, cancelButton)
56 .then(answer => {
57 if (answer === cancelButton) {
58 reject(ErrorHelper.getInternalError(InternalErrorCode.UserCancelledExpoLogin));
59 }
60 resolve("");
61 }, reject);
62 });
63 }
64 )
65 .then(() =>
66 XDL.setOptions(this.projectPath, { packagerPort: this.packager.port })
67 )
68 .then(() =>
69 XDL.startExponentServer(this.projectPath)
70 )
71 .then(() =>
72 XDL.startTunnels(this.projectPath)
73 )
74 .then(() =>
75 XDL.getUrl(this.projectPath, { dev: true, minify: false })
76 ).then(exponentUrl => {
77 return "exp://" + url.parse(exponentUrl).host;
78 })
79 .catch(reason => {
80 return Q.reject<string>(reason);
81 })
82 .then(exponentUrl => {
83 let exponentPage = vscode.window.createWebviewPanel("Expo QR Code", "Expo QR Code", vscode.ViewColumn.Two, { });
84 exponentPage.webview.html = this.qrCodeContentProvider.provideTextDocumentContent(vscode.Uri.parse(exponentUrl));
85 return exponentUrl;
86 })
87 .then(exponentUrl => {
88 if (!exponentUrl) {
89 return Q.reject<void>(ErrorHelper.getInternalError(InternalErrorCode.ExpectedExponentTunnelPath));
90 }
91 this.exponentTunnelPath = exponentUrl;
92 const outputMessage = localize("ApplicationIsRunningOnExponentOpenToSeeIt", "Application is running on Expo. Open your Expo app at {0} to see it.", this.exponentTunnelPath);
93 this.logger.info(outputMessage);
94
95 return Q.resolve(void 0);
96 });
97 });
98 }
99
100 public beforeStartPackager(): Q.Promise<void> {
101 return this.exponentHelper.configureExponentEnvironment();
102 }
103
104 public enableJSDebuggingMode(): Q.Promise<void> {
105 this.logger.info(localize("ApplicationIsRunningOnExponentShakeDeviceForRemoteDebugging", "Application is running on Expo. Please shake device and select 'Debug JS Remotely' to enable debugging."));
106 return Q.resolve<void>(void 0);
107 }
108
109 public getRunArguments(): string[] {
110 return [];
111 }
112}
113