microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
57deace7f89d033ec2db480ff2484490b194b54c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/exponent/exponentPlatform.ts

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