Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: delete android emulator #104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion MiniSim/MenuItems/SubMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ enum SubMenuItems {
accessibilityDescription: "Delete simulator"
)
}

struct DeleteEmulator: SubMenuActionItem {
let title = NSLocalizedString("Delete emulator", comment: "")
let tag = Tags.delete.rawValue
let bootsDevice = false
let needBootedDevice = false
let image = NSImage(
systemSymbolName: "trash",
accessibilityDescription: "Delete emulator"
)
}
}

extension SubMenuItems {
Expand All @@ -131,7 +142,8 @@ extension SubMenuItems {
ColdBoot(),
NoAudio(),
ToggleA11y(),
Paste()
Paste(),
DeleteEmulator()
]

static var ios: [SubMenuItem] = [
Expand Down
5 changes: 5 additions & 0 deletions MiniSim/Service/Adb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class ADB: ADBProtocol {
case home = "/Android/sdk"
case emulator = "/emulator/emulator"
case adb = "/platform-tools/adb"
case avd = "/cmdline-tools/latest/bin/avdmanager"
}

/**
Expand All @@ -47,6 +48,10 @@ final class ADB: ADBProtocol {
try getAndroidHome() + Paths.adb.rawValue
}

static func getAvdPath() throws -> String {
try getAndroidHome() + Paths.avd.rawValue
}

/**
Checks if passed path exists and points to `ANDROID_HOME`.
*/
Expand Down
30 changes: 28 additions & 2 deletions MiniSim/Service/DeviceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
try shellOut(to: ProcessPaths.xcrun.rawValue, arguments: ["simctl", "delete", uuid])
}

static func handleiOSAction(device: Device, commandTag: SubMenuItems.Tags, itemName: String) {

Check warning on line 305 in MiniSim/Service/DeviceService.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
switch commandTag {
case .copyName:
NSPasteboard.general.copyToPasteboard(text: device.name)
Expand Down Expand Up @@ -413,8 +413,19 @@
try shellOut(to: "\(adbPath) -s \(deviceId) shell input text \"\(formattedText)\"")
}

static func deleteEmulator(device: Device) throws {
let avdPath = try ADB.getAvdPath()
let adbPath = try ADB.getAdbPath()
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)\"")
}

static func handleAndroidAction(device: Device, commandTag: SubMenuItems.Tags, itemName: String) {

Check warning on line 428 in MiniSim/Service/DeviceService.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 15 (cyclomatic_complexity)
queue.async {
do {
switch commandTag {
case .coldBoot:
Expand Down Expand Up @@ -447,12 +458,27 @@
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?",
message: "Are you sure you want to delete this Emulator?"
)
if result { return }
queue.async {
do {
try DeviceService.deleteEmulator(device: device)
DeviceService.showSuccessMessage(title: "Emulator deleted!", message: device.name)
NotificationCenter.default.post(name: .deviceDeleted, object: nil)
} catch {
NSAlert.showError(message: error.localizedDescription)
}
}
default:
break
}
} catch {
NSAlert.showError(message: error.localizedDescription)
}
}
}
}

Check warning on line 484 in MiniSim/Service/DeviceService.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

File Length Violation: File should contain 400 lines or less: currently contains 484 (file_length)
Loading