import * as nls from "vscode-nls" ; import { QuickPickOptions , window } from "vscode" ; import { IMobileTarget , MobileTarget } from "./mobileTarget" ; import { TargetType } from "../debugger/cordovaDebugSession" ; nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone , } ) ( ) ; const localize = nls . loadMessageBundle ( ) ; export abstract class MobileTargetManager { protected targets ? : IMobileTarget [ ] ; public abstract collectTargets ( targetType ? ) ; public abstract selectAndPrepareTarget ( filter ? ) ; public async isVirtualTarget ( target ) { if ( target . includes ( "device" ) ) { return false ; } if ( target . includes ( "emulator" ) ) { return true ; } throw new Error ( localize ( "CouldNotRecognizeTargetType" , "Could not recognize type of the target {0}" , target ) ) ; } protected abstract launchSimulator ( emulatorTarget ) ; protected abstract startSelection ( filter ? ) ; protected async getTargetList ( filter ? ) { if ( ! this . targets ) { await this . collectTargets ( ) ; } return filter ? this . targets . filter ( filter ) : this . targets ; } protected async selectTarget ( filter ? ) { const targetList = await this . getTargetList ( filter ) ; let result = targetList [ 0 ] ?. name || targetList [ 0 ] ?. id ; if ( targetList . length > 1 ) { const quickPickOptions = { ignoreFocusOut : true , canPickMany : false , placeHolder : localize ( "SelectTargetDevice" , "Select target device for launch application" ) , } ; result = await window . showQuickPick ( targetList . map ( target => target ?. name || target ?. id ) , quickPickOptions ) ; } return targetList . find ( target => target . name === result || target . id === result ) ; } }