microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/commands/launchAndroidEmulator.ts
28lines · modeblame
36a21645Heniker4 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 assert from "assert"; | |
| 5 | import { ErrorHelper } from "../../common/error/errorHelper"; | |
| 6 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; | |
| 7 | import { AdbHelper } from "../android/adb"; | |
| 8 | import { AndroidTargetManager } from "../android/androidTargetManager"; | |
| 9 | import { TargetType } from "../generalPlatform"; | |
| 10 | import { Command } from "./util/command"; | |
| 11 | | |
| 12 | // #todo> codeName differs from Class Name | |
| 13 | export class LaunchAndroidEmulator extends Command { | |
| 14 | codeName = "launchAndroidSimulator"; | |
| 15 | label = "Launch Android Emulator"; | |
| 16 | error = ErrorHelper.getInternalError(InternalErrorCode.FailedToStartAndroidEmulator); | |
| 17 | | |
| 18 | async baseFn(): Promise<void> { | |
| 19 | assert(this.project); | |
| 20 | | |
| 21 | const projectPath = this.project.getPackager().getProjectPath(); | |
| 22 | const nodeModulesRoot = this.project.getOrUpdateNodeModulesRoot(); | |
| 23 | const adbHelper = new AdbHelper(projectPath, nodeModulesRoot); | |
| 24 | const androidEmulatorManager = new AndroidTargetManager(adbHelper); | |
| 25 | await androidEmulatorManager.collectTargets(TargetType.Simulator); | |
| 26 | await androidEmulatorManager.selectAndPrepareTarget(target => target.isVirtualTarget); | |
| 27 | } | |
| 28 | } |