feat: add destination-specific global shortcuts

This commit is contained in:
Valdemar Lorenzen
2026-10-15 15:00:51 +02:00
parent 8946b19b7a
commit 6bb2b4a482
12 changed files with 383 additions and 53 deletions
+30 -10
View File
@@ -36,6 +36,8 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
private var translation: TranslationController?
private var emojiPicker: EmojiPickerController?
private var isCommandOpen: Bool { translation != nil || emojiPicker != nil }
private var activeCommand: Application.Command?
private var pendingPresentation: (() -> Void)?
init(history: LaunchHistory = LaunchHistory(), uninstaller: ApplicationUninstaller = ApplicationUninstaller()) {
self.history = history
@@ -100,15 +102,16 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
currencyTask?.cancel()
}
func present() {
(window as? LauncherPanel)?.beginNumberHintSession()
if launcherFrameBeforeReview != nil || isCommandOpen {
showWindow(nil)
NSApp.activate()
window?.makeKeyAndOrderFront(nil)
(window as? LauncherPanel)?.sampleNumberHints()
func present(command: Application.Command? = nil) {
guard !isLaunching, window?.attachedSheet == nil else { return }
if launcherFrameBeforeReview != nil {
pendingPresentation = { [weak self] in self?.present(command: command) }
uninstallReview?.goBack()
return
}
closeCommand()
actions.close()
(window as? LauncherPanel)?.beginNumberHintSession()
let frontmost = NSWorkspace.shared.frontmostApplication
if frontmost?.processIdentifier != ProcessInfo.processInfo.processIdentifier {
previousApplication = frontmost
@@ -124,14 +127,21 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
(window as? LauncherPanel)?.sampleNumberHints()
(searchField.currentEditor() as? NSTextView)?.insertionPointColor = SunsetPalette.accent
refreshApplications()
if let command {
showCommand(command)
history.recordLaunch(of: Application(command: command))
}
}
func toggle() {
func toggle(command: Application.Command? = nil) {
guard !isLaunching, window?.attachedSheet == nil else { return }
if window?.isVisible == true, window?.isKeyWindow == true {
if window?.isVisible == true, window?.isKeyWindow == true,
launcherFrameBeforeReview == nil, activeCommand == command {
closeCommand()
actions.close()
dismiss()
} else {
present()
present(command: command)
}
}
@@ -728,6 +738,9 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
self.openButton.keyEquivalent = "\r"
self.updateOpenButton()
self.window?.makeFirstResponder(self.searchField)
let pending = self.pendingPresentation
self.pendingPresentation = nil
pending?()
}
}
}
@@ -790,8 +803,14 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
emojiPicker?.goBack()
}
private func closeCommand() {
translation?.goBack()
emojiPicker?.close()
}
private func showCommand(_ command: Application.Command) {
guard !isCommandOpen, let content = window?.contentView else { return }
activeCommand = command
let controller: NSViewController
let placeholder: String
let accessibilityLabel: String
@@ -820,6 +839,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
controller.view.removeFromSuperview()
self.translation = nil
self.emojiPicker = nil
self.activeCommand = nil
self.commandBack.isHidden = true
self.commandBack.target = nil
self.searchSymbol.isHidden = false