microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/generalMobilePlatform.ts
49lines · 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 | |
| 4 | import * as Q from "q"; |
| 5 | |
| 6 | import {Log} from "../common/log/log"; |
| 7 | import {IRunOptions} from "../common/launchArgs"; |
| 8 | import {RemoteExtension} from "../common/remoteExtension"; |
| 9 | import {Packager} from "../common/packager"; |
| 10 | |
| 11 | export class GeneralMobilePlatform { |
| 12 | protected projectPath: string; |
| 13 | protected remoteExtension: RemoteExtension; |
| 14 | protected platformName: string; |
| 15 | |
| 16 | constructor(protected runOptions: IRunOptions, { remoteExtension = null } = {}) { |
| 17 | this.platformName = this.runOptions.platform; |
| 18 | this.projectPath = this.runOptions.projectRoot; |
| 19 | this.remoteExtension = (remoteExtension) ? remoteExtension : RemoteExtension.atProjectRootPath(runOptions.projectRoot); |
| 20 | } |
| 21 | |
| 22 | public runApp(): Q.Promise<void> { |
| 23 | Log.logMessage("Conected to packager. You can now open your app in the simulator."); |
| 24 | return Q.resolve<void>(void 0); |
| 25 | } |
| 26 | |
| 27 | public enableJSDebuggingMode(): Q.Promise<void> { |
| 28 | Log.logMessage("Debugger ready. Enable remote debugging in app."); |
| 29 | return Q.resolve<void>(void 0); |
| 30 | } |
| 31 | |
| 32 | public startPackager(): Q.Promise<void> { |
| 33 | return this.remoteExtension.getPackagerPort().then(port => { |
| 34 | return Packager.isPackagerRunning(Packager.getHostForPort(port)) |
| 35 | .then(isRunning => { |
| 36 | if (isRunning) { |
| 37 | Log.logMessage("Attaching to running packager at port: " + port); |
| 38 | return Q.resolve<void>(void 0); |
| 39 | } |
| 40 | return this.remoteExtension.startPackager(); |
| 41 | }); |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | public prewarmBundleCache(): Q.Promise<void> { |
| 46 | // generalMobilePlatform should do nothing here. Method should be overriden by children for specific behavior. |
| 47 | return Q.resolve<void>(void 0); |
| 48 | } |
| 49 | } |
| 50 | |