Skip to content

Commit dc47e20

Browse files
committed
feat: add option to hold shift when deleting simulators to skip alert
1 parent 26bb86f commit dc47e20

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

MiniSim/Menu.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ class Menu: NSMenu {
9898
guard let tag = SubMenuItems.Tags(rawValue: sender.tag) else { return }
9999
guard let device = getDeviceByName(name: sender.parent?.title ?? "") else { return }
100100

101+
let skipConfirmation = NSEvent.modifierFlags.contains(.shift)
102+
101103
actionExecutor.execute(
102104
device: device,
103105
commandTag: tag,
104-
itemName: sender.title
106+
itemName: sender.title,
107+
skipConfirmation: skipConfirmation
105108
)
106109
}
107110

MiniSim/Service/ActionExecutor.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class ActionExecutor {
1111
func execute(
1212
device: Device,
1313
commandTag: SubMenuItems.Tags,
14-
itemName: String
14+
itemName: String,
15+
skipConfirmation: Bool = false
1516
) {
1617
let action: Action
1718

@@ -20,13 +21,15 @@ class ActionExecutor {
2021
action = AndroidActionFactory.createAction(
2122
for: commandTag,
2223
device: device,
23-
itemName: itemName
24+
itemName: itemName,
25+
skipConfirmation: skipConfirmation
2426
)
2527
case .ios:
2628
action = IOSActionFactory.createAction(
2729
for: commandTag,
2830
device: device,
29-
itemName: itemName
31+
itemName: itemName,
32+
skipConfirmation: skipConfirmation
3033
)
3134
}
3235

MiniSim/Service/ActionFactory.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import AppKit
22
import Foundation
33

44
protocol ActionFactory {
5-
static func createAction(for tag: SubMenuItems.Tags, device: Device, itemName: String) -> Action
5+
static func createAction(for tag: SubMenuItems.Tags, device: Device, itemName: String, skipConfirmation: Bool) -> Action
66
}
77

88
class AndroidActionFactory: ActionFactory {
9-
static func createAction(for tag: SubMenuItems.Tags, device: Device, itemName: String) -> any Action {
9+
static func createAction(for tag: SubMenuItems.Tags, device: Device, itemName: String, skipConfirmation: Bool = false) -> any Action {
1010
switch tag {
1111
case .copyName:
1212
return CopyNameAction(device: device)
@@ -21,7 +21,7 @@ class AndroidActionFactory: ActionFactory {
2121
case .paste:
2222
return PasteClipboardAction(device: device)
2323
case .delete:
24-
return DeleteAction(device: device)
24+
return DeleteAction(device: device, skipConfirmation: skipConfirmation)
2525
case .customCommand:
2626
return CustomCommandAction(device: device, itemName: itemName)
2727
case .logcat:
@@ -31,7 +31,7 @@ class AndroidActionFactory: ActionFactory {
3131
}
3232

3333
class IOSActionFactory: ActionFactory {
34-
static func createAction(for tag: SubMenuItems.Tags, device: Device, itemName: String) -> any Action {
34+
static func createAction(for tag: SubMenuItems.Tags, device: Device, itemName: String, skipConfirmation: Bool = false) -> any Action {
3535
switch tag {
3636
case .copyName:
3737
return CopyNameAction(device: device)
@@ -42,7 +42,7 @@ class IOSActionFactory: ActionFactory {
4242
case .coldBoot:
4343
return ColdBootCommand(device: device)
4444
case .delete:
45-
return DeleteAction(device: device)
45+
return DeleteAction(device: device, skipConfirmation: skipConfirmation)
4646
default:
4747
fatalError("Unhandled action tag: \(tag)")
4848
}

MiniSim/Service/Actions.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ class CopyNameAction: Action {
4444

4545
class DeleteAction: Action {
4646
let device: Device
47+
let skipConfirmation: Bool
4748

48-
init(device: Device) {
49+
init(device: Device, skipConfirmation: Bool = false) {
4950
self.device = device
51+
self.skipConfirmation = skipConfirmation
5052
}
5153

5254
func showQuestionDialog() -> Bool {
53-
!NSAlert.showQuestionDialog(
55+
guard !skipConfirmation else { return false }
56+
return !NSAlert.showQuestionDialog(
5457
title: "Are you sure?",
5558
message: "Are you sure you want to delete this device?"
5659
)

0 commit comments

Comments
 (0)