fix: run action-only commands without presenting launcher

This commit is contained in:
2026-10-18 18:56:56 +02:00
parent a68694e66b
commit 0074c88e5d
5 changed files with 91 additions and 19 deletions
+31 -13
View File
@@ -131,6 +131,11 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
func present(command: Application.Command? = nil) {
guard !isLaunching, window?.attachedSheet == nil else { return }
if let command, !command.presentsView {
guard launcherFrameBeforeReview == nil else { return }
executeCommand(command)
return
}
if launcherFrameBeforeReview != nil {
pendingPresentation = { [weak self] in self?.present(command: command) }
uninstallReview?.goBack()
@@ -147,7 +152,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
restorePosition()
updateResults()
if let command {
showCommand(command)
executeCommand(command)
}
window?.deminiaturize(nil)
showWindow(nil)
@@ -738,7 +743,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
private func openApplication(_ application: Application) {
guard !isLaunching, !isCommandOpen, launcherFrameBeforeReview == nil, window?.attachedSheet == nil else { return }
if let command = application.command {
showCommand(command)
executeCommand(command, dismissOnSuccess: true)
return
}
(window as? LauncherPanel)?.resetNumberHints()
@@ -804,27 +809,41 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
return true
}
private func toggleTheme() {
actions.close(animated: false)
private func runAction(_ command: Application.Command, dismissOnSuccess: Bool) {
let action: @MainActor () async throws -> Void
switch command {
case .toggleTheme: action = toggleSystemTheme
case .translate, .emoji, .notes:
preconditionFailure("View commands must be presented, not run as actions")
}
if dismissOnSuccess { actions.close(animated: false) }
isLaunching = true
updateOpenButton()
Task {
do {
try await toggleSystemTheme()
history.recordLaunch(of: Application(command: .toggleTheme))
try await action()
history.recordLaunch(of: Application(command: command))
isLaunching = false
dismiss()
if dismissOnSuccess { dismiss() }
} catch {
isLaunching = false
let alert = NSAlert(error: error)
alert.messageText = "Couldn’t toggle system theme"
if let window { await alert.beginSheetModal(for: window) }
alert.messageText = "Couldn’t run \(Application(command: command).name)"
if let window, window.isVisible {
await alert.beginSheetModal(for: window)
} else {
alert.runModal()
}
}
isLaunching = false
updateOpenButton()
}
}
private func showCommand(_ command: Application.Command) {
private func executeCommand(_ command: Application.Command, dismissOnSuccess: Bool = false) {
guard command.presentsView else {
runAction(command, dismissOnSuccess: dismissOnSuccess)
return
}
guard !isCommandOpen, let content = window?.contentView else { return }
let controller: NSViewController
let placeholder: String
@@ -865,8 +884,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
placeholder = "Conjure Notes"
accessibilityLabel = "Conjure Notes"
case .toggleTheme:
toggleTheme()
return
preconditionFailure("Action commands must run without presenting a view")
}
activeCommand = command
history.recordLaunch(of: Application(command: command))