@@ -413,8 +413,19 @@ extension DeviceService {
413413 try shellOut ( to: " \( adbPath) -s \( deviceId) shell input text \" \( formattedText) \" " )
414414 }
415415
416+ static func deleteEmulator( device: Device ) throws {
417+ let avdPath = try ADB . getAvdPath ( )
418+ let adbPath = try ADB . getAdbPath ( )
419+ if device. booted {
420+ guard let deviceId = device. identifier else {
421+ throw DeviceError . deviceNotFound
422+ }
423+ try shellOut ( to: " \( adbPath) -s \( deviceId) emu kill " )
424+ }
425+ try shellOut ( to: " \( avdPath) delete avd -n \" \( device. name) \" " )
426+ }
427+
416428 static func handleAndroidAction( device: Device , commandTag: SubMenuItems . Tags , itemName: String ) {
417- queue. async {
418429 do {
419430 switch commandTag {
420431 case . coldBoot:
@@ -447,12 +458,27 @@ extension DeviceService {
447458 if let command = DeviceService . getCustomCommand ( platform: . android, commandName: itemName) {
448459 try DeviceService . runCustomCommand ( device, command: command)
449460 }
461+
462+ case . delete:
463+ let result = !NSAlert. showQuestionDialog (
464+ title: " Are you sure? " ,
465+ message: " Are you sure you want to delete this Emulator? "
466+ )
467+ if result { return }
468+ queue. async {
469+ do {
470+ try DeviceService . deleteEmulator ( device: device)
471+ DeviceService . showSuccessMessage ( title: " Emulator deleted! " , message: device. name)
472+ NotificationCenter . default. post ( name: . deviceDeleted, object: nil )
473+ } catch {
474+ NSAlert . showError ( message: error. localizedDescription)
475+ }
476+ }
450477 default :
451478 break
452479 }
453480 } catch {
454481 NSAlert . showError ( message: error. localizedDescription)
455482 }
456- }
457483 }
458484}
0 commit comments