feat: add hide/show app shortcut
This commit is contained in:
1 parent
2b752efb72
commit
6be1c2ccca
4 files changed
+32
-12
No files matched your search
@@ -17,8 +17,9 @@ class Preferences {
|
||||
"previousWindowShortcut": "⇧⇥",
|
||||
"cancelShortcut": "⎋",
|
||||
"closeWindowShortcut": "W",
|
||||
"quitAppShortcut": "Q",
|
||||
"minDeminWindowShortcut": "M",
|
||||
"quitAppShortcut": "Q",
|
||||
"hideShowAppShortcut": "H",
|
||||
"arrowKeysEnabled": true,
|
||||
"mouseHoverEnabled": true,
|
||||
"showMinimizedWindows": true,
|
||||
@@ -55,8 +56,9 @@ class Preferences {
|
||||
static var previousWindowShortcut: String { defaults.string(forKey: "previousWindowShortcut")! }
|
||||
static var cancelShortcut: String { defaults.string(forKey: "cancelShortcut")! }
|
||||
static var closeWindowShortcut: String { defaults.string(forKey: "closeWindowShortcut")! }
|
||||
static var quitAppShortcut: String { defaults.string(forKey: "quitAppShortcut")! }
|
||||
static var minDeminWindowShortcut: String { defaults.string(forKey: "minDeminWindowShortcut")! }
|
||||
static var quitAppShortcut: String { defaults.string(forKey: "quitAppShortcut")! }
|
||||
static var hideShowAppShortcut: String { defaults.string(forKey: "hideShowAppShortcut")! }
|
||||
static var arrowKeysEnabled: Bool { defaults.bool(forKey: "arrowKeysEnabled") }
|
||||
static var mouseHoverEnabled: Bool { defaults.bool(forKey: "mouseHoverEnabled") }
|
||||
static var showMinimizedWindows: Bool { defaults.bool(forKey: "showMinimizedWindows") }
|
||||
|
||||
+13
-2
@@ -72,15 +72,26 @@ class Window {
|
||||
}
|
||||
}
|
||||
|
||||
func minDemin() {
|
||||
DispatchQueues.accessibilityCommands.async { [weak self] in
|
||||
self?.axUiElement.minDeminWindow()
|
||||
}
|
||||
}
|
||||
|
||||
func quitApp() {
|
||||
DispatchQueues.accessibilityCommands.async { [weak self] in
|
||||
self?.application.runningApplication.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
func minDemin() {
|
||||
func hideShowApp() {
|
||||
DispatchQueues.accessibilityCommands.async { [weak self] in
|
||||
self?.axUiElement.minDeminWindow()
|
||||
guard let self = self else { return }
|
||||
if self.application.runningApplication.isHidden {
|
||||
self.application.runningApplication.unhide()
|
||||
} else {
|
||||
self.application.runningApplication.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -100,12 +100,16 @@ class App: NSApplication, NSApplicationDelegate {
|
||||
Windows.focusedWindow()?.close()
|
||||
}
|
||||
|
||||
func minDeminSelectedWindow() {
|
||||
Windows.focusedWindow()?.minDemin()
|
||||
}
|
||||
|
||||
func quitSelectedApp() {
|
||||
Windows.focusedWindow()?.quitApp()
|
||||
}
|
||||
|
||||
func minDeminSelectedWindow() {
|
||||
Windows.focusedWindow()?.minDemin()
|
||||
func hideShowSelectedApp() {
|
||||
Windows.focusedWindow()?.hideShowApp()
|
||||
}
|
||||
|
||||
func focusTarget() {
|
||||
|
||||
@@ -18,8 +18,9 @@ class GeneralTab: NSViewController, PreferencePane {
|
||||
let previousWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Select previous window", comment: ""), "previousWindowShortcut", Preferences.previousWindowShortcut, labelPosition: .right)
|
||||
let cancelShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Cancel and hide", comment: ""), "cancelShortcut", Preferences.cancelShortcut, labelPosition: .right)
|
||||
let closeWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Close window", comment: ""), "closeWindowShortcut", Preferences.closeWindowShortcut, labelPosition: .right)
|
||||
let quitAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Quit app", comment: ""), "quitAppShortcut", Preferences.quitAppShortcut, labelPosition: .right)
|
||||
let minDeminWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Minimize/Deminimize window", comment: ""), "minDeminWindowShortcut", Preferences.minDeminWindowShortcut, labelPosition: .right)
|
||||
let quitAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Quit app", comment: ""), "quitAppShortcut", Preferences.quitAppShortcut, labelPosition: .right)
|
||||
let hideShowAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hide/Show app", comment: ""), "hideShowAppShortcut", Preferences.hideShowAppShortcut, labelPosition: .right)
|
||||
let enableArrows = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Arrow keys", comment: ""), "arrowKeysEnabled", extraAction: GeneralTab.arrowKeysEnabledCallback, labelPosition: .right)
|
||||
let enableMouse = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Mouse hover", comment: ""), "mouseHoverEnabled", labelPosition: .right)
|
||||
let holdAndPress = StackView(holdShortcut)
|
||||
@@ -30,7 +31,7 @@ class GeneralTab: NSViewController, PreferencePane {
|
||||
let screensToShow = dropdown("screensToShow", ScreensToShowPreference.allCases)
|
||||
let showMinimizedWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Minimized", comment: ""), "showMinimizedWindows", labelPosition: .right))
|
||||
let showHiddenWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Hidden", comment: ""), "showHiddenWindows", labelPosition: .right))
|
||||
let shortcuts = StackView([nextWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, quitAppShortcut, minDeminWindowShortcut].map { (view: [NSView]) in StackView(view) }, .vertical)
|
||||
let shortcuts = StackView([nextWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut].map { (view: [NSView]) in StackView(view) }, .vertical)
|
||||
let toShowDropdowns = StackView([appsToShow, spacesToShow, screensToShow], .vertical)
|
||||
let toShowCheckboxes = StackView([showMinimizedWindows, showHiddenWindows], .vertical)
|
||||
let toShowExplanations = LabelAndControl.makeLabel(NSLocalizedString("Show the following windows:", comment: ""))
|
||||
@@ -47,7 +48,7 @@ class GeneralTab: NSViewController, PreferencePane {
|
||||
grid.fit()
|
||||
|
||||
GeneralTab.shortcutsDependentOnHoldShortcut.append(contentsOf: [enableArrows[0] as! NSControl] +
|
||||
[nextWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, quitAppShortcut, minDeminWindowShortcut].map { $0[0] as! NSControl })
|
||||
[nextWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut].map { $0[0] as! NSControl })
|
||||
GeneralTab.arrowKeysEnabledCallback(enableArrows[0] as! NSControl)
|
||||
startAtLoginCallback(startAtLogin[1] as! NSControl)
|
||||
|
||||
@@ -63,7 +64,7 @@ class GeneralTab: NSViewController, PreferencePane {
|
||||
removeShortcutIfExists(controlId, type) // remove the previous shortcut
|
||||
shortcutActions[controlId] = ShortcutAction(shortcut: shortcut, actionHandler: { _ in
|
||||
let isShortcutInitiatingTheApp = ["previousWindowShortcut", "nextWindowShortcut"].contains(controlId)
|
||||
let isShortcutWithUiShown = ["←", "→", "closeWindowShortcut", "quitAppShortcut", "minDeminWindowShortcut"].contains(controlId)
|
||||
let isShortcutWithUiShown = ["←", "→", "closeWindowShortcut", "minDeminWindowShortcut", "quitAppShortcut", "hideShowAppShortcut"].contains(controlId)
|
||||
App.app.uiWorkShouldBeDone = isShortcutInitiatingTheApp || isShortcutWithUiShown
|
||||
if isShortcutInitiatingTheApp {
|
||||
App.app.appIsBeingUsed = true
|
||||
@@ -102,10 +103,12 @@ class GeneralTab: NSViewController, PreferencePane {
|
||||
return { App.app.hideUi() }
|
||||
} else if controlId == "closeWindowShortcut" {
|
||||
return { App.app.closeSelectedWindow() }
|
||||
} else if controlId == "quitAppShortcut" {
|
||||
return { App.app.quitSelectedApp() }
|
||||
} else if controlId == "minDeminWindowShortcut" {
|
||||
return { App.app.minDeminSelectedWindow() }
|
||||
} else if controlId == "quitAppShortcut" {
|
||||
return { App.app.quitSelectedApp() }
|
||||
} else if controlId == "hideShowAppShortcut" {
|
||||
return { App.app.hideShowSelectedApp() }
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user