Remove explicit passing of window to shortcuts
Some checks are pending
Deploy Docs / publish (push) Waiting to run
SwiftLint / SwiftLint (push) Waiting to run

This commit is contained in:
david-swift 2025-10-30 21:55:38 +01:00
parent 04c77831b5
commit edb6a81812

View File

@ -45,8 +45,11 @@ extension Button {
/// - window: The application window. /// - window: The application window.
/// - active: Whether the keyboard shortcut is active. /// - active: Whether the keyboard shortcut is active.
/// - Returns: The button. /// - Returns: The button.
public func keyboardShortcut(_ shortcut: String, window: AdwaitaWindow, active: Bool = true) -> AnyView { public func keyboardShortcut(_ shortcut: String, active: Bool = true) -> AnyView {
onUpdate { inspect { _, data, _ in
guard let window = data.sceneStorage.pointer as? AdwaitaWindow else {
return
}
if active { if active {
window.app.addKeyboardShortcut(shortcut, id: shortcut, window: window) { self.clicked?() } window.app.addKeyboardShortcut(shortcut, id: shortcut, window: window) { self.clicked?() }
} else { } else {
@ -63,12 +66,15 @@ extension Button {
/// - window: The application. /// - window: The application.
/// - active: Whether the keyboard shortcut is active. /// - active: Whether the keyboard shortcut is active.
/// - Returns: The button. /// - Returns: The button.
public func keyboardShortcut(_ shortcut: String, app: AdwaitaApp, active: Bool = true) -> AnyView { public func appKeyboardShortcut(_ shortcut: String, active: Bool = true) -> AnyView {
onUpdate { inspect { _, data, _ in
guard let window = data.sceneStorage.pointer as? AdwaitaWindow else {
return
}
if active { if active {
app.addKeyboardShortcut(shortcut, id: shortcut) { self.clicked?() } window.app.addKeyboardShortcut(shortcut, id: shortcut) { self.clicked?() }
} else { } else {
app.removeKeyboardShortcut(id: shortcut) window.app.removeKeyboardShortcut(id: shortcut)
} }
} }
} }