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
@@ -0,0 +1,34 @@
import AppKit
import ConjureKit
import Testing
@testable import Conjure
@Test @MainActor func activationAlwaysTargetsRequestedViewAndClearsPreviousTool() throws {
_ = NSApplication.shared
let suite = "ConjureDestination.\(UUID().uuidString)"
let defaults = UserDefaults(suiteName: suite)!
defer { defaults.removePersistentDomain(forName: suite) }
let launcher = LauncherWindowController(history: LaunchHistory(defaults: defaults, now: { Date(timeIntervalSinceReferenceDate: 12_000) }))
let window = try #require(launcher.window)
defer { window.orderOut(nil) }
func descendants(_ view: NSView) -> [NSView] { [view] + view.subviews.flatMap(descendants) }
let content = try #require(window.contentView)
let search = try #require(descendants(content).compactMap { $0 as? NSSearchField }.first)
launcher.present(command: .emoji)
#expect(descendants(content).contains { $0 is NSCollectionView })
search.stringValue = "happy"
launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search))
window.orderOut(nil)
launcher.toggle()
#expect(!descendants(content).contains { $0 is NSCollectionView })
#expect(search.stringValue.isEmpty)
#expect(search.accessibilityLabel() == "Search applications, calculate, or convert units and currencies")
launcher.toggle(command: .translate)
#expect(search.accessibilityLabel() == "English text to translate into Japanese")
launcher.toggle(command: .emoji)
#expect(search.accessibilityLabel() == "Search emoji")
#expect(search.stringValue.isEmpty)
launcher.present()
#expect(!descendants(content).contains { $0 is NSCollectionView })
#expect(search.accessibilityLabel() == "Search applications, calculate, or convert units and currencies")
}