Skip to content

Commit

Permalink
fix deleting booted devices
Browse files Browse the repository at this point in the history
  • Loading branch information
gokul1099 authored and okwasniewski committed Nov 20, 2023
1 parent fb32c77 commit 4b82b0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MiniSim/MenuItems/SubMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ enum SubMenuItems {
let needBootedDevice = false
let image = NSImage(
systemSymbolName: "trash",
accessibilityDescription: "Delete simulator"
accessibilityDescription: "Delete emulator"
)

Check warning on line 132 in MiniSim/MenuItems/SubMenuItem.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 132 in MiniSim/MenuItems/SubMenuItem.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Vertical Whitespace before Closing Braces Violation: Don't include vertical whitespace (empty line) before closing braces (vertical_whitespace_closing_braces)
}
Expand Down
16 changes: 6 additions & 10 deletions MiniSim/Service/DeviceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,10 @@ extension DeviceService {
static func deleteEmulator(device: Device) throws {
let avdPath = try ADB.getAvdPath()
let adbPath = try ADB.getAdbPath()

let activeDevices = try shellOut(to: "\(adbPath) devices")
guard let deviceId = device.identifier else {
throw DeviceError.deviceNotFound
}

let isEmulatorActive = activeDevices.contains(deviceId)
if isEmulatorActive{
if device.booted {
guard let deviceId = device.identifier else {
throw DeviceError.deviceNotFound
}
try shellOut(to: "\(adbPath) -s \(deviceId) emu kill")
}
try shellOut(to: "\(avdPath) delete avd -n \"\(device.name)\"")
Expand Down Expand Up @@ -462,7 +458,7 @@ extension DeviceService {
if let command = DeviceService.getCustomCommand(platform: .android, commandName: itemName) {
try DeviceService.runCustomCommand(device, command: command)
}

case .delete:
let result = !NSAlert.showQuestionDialog(
title: "Are you sure?",
Expand All @@ -472,7 +468,7 @@ extension DeviceService {
queue.async {
do {
try DeviceService.deleteEmulator(device: device)
DeviceService.showSuccessMessage(title: "Simulator deleted!", message: device.name)
DeviceService.showSuccessMessage(title: "Emulator deleted!", message: device.name)
NotificationCenter.default.post(name: .deviceDeleted, object: nil)
} catch {
NSAlert.showError(message: error.localizedDescription)
Expand Down

0 comments on commit 4b82b0e

Please sign in to comment.