feat: quitting an app twice force-quits it (closes #1529)
This commit is contained in:
1 parent
be8631e90c
commit
bfcbaacec7
3 files changed
+34
-33
No files matched your search
+32
-12
@@ -14,6 +14,7 @@ class Application: NSObject {
|
|||||||
var dockLabel: String?
|
var dockLabel: String?
|
||||||
var pid: pid_t!
|
var pid: pid_t!
|
||||||
var focusedWindow: Window? = nil
|
var focusedWindow: Window? = nil
|
||||||
|
var alreadyRequestedToQuit = false
|
||||||
|
|
||||||
init(_ runningApplication: NSRunningApplication) {
|
init(_ runningApplication: NSRunningApplication) {
|
||||||
self.runningApplication = runningApplication
|
self.runningApplication = runningApplication
|
||||||
@@ -103,6 +104,37 @@ class Application: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addWindowslessAppsIfNeeded() -> [Window]? {
|
||||||
|
if !Preferences.hideWindowlessApps &&
|
||||||
|
runningApplication.activationPolicy == .regular &&
|
||||||
|
!runningApplication.isTerminated &&
|
||||||
|
(Windows.list.firstIndex { $0.application.pid == pid }) == nil {
|
||||||
|
let window = Window(self)
|
||||||
|
Windows.appendAndUpdateFocus(window)
|
||||||
|
return [window]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func hideOrShow() {
|
||||||
|
if runningApplication.isHidden {
|
||||||
|
runningApplication.unhide()
|
||||||
|
} else {
|
||||||
|
runningApplication.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func quit() {
|
||||||
|
// only let power users quit Finder if they opt-in
|
||||||
|
if runningApplication.bundleIdentifier == "com.apple.finder" && !Preferences.finderShowsQuitMenuItem { return }
|
||||||
|
if alreadyRequestedToQuit {
|
||||||
|
runningApplication.forceTerminate()
|
||||||
|
} else {
|
||||||
|
runningApplication.terminate()
|
||||||
|
alreadyRequestedToQuit = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func addWindows(_ axWindows: [(AXUIElement, CGWindowID, String?, Bool, Bool, CGPoint?, CGSize?)]) -> [Window] {
|
private func addWindows(_ axWindows: [(AXUIElement, CGWindowID, String?, Bool, Bool, CGPoint?, CGSize?)]) -> [Window] {
|
||||||
let windows: [Window] = axWindows.compactMap { (axUiElement, wid, axTitle, isFullscreen, isMinimized, position, size) in
|
let windows: [Window] = axWindows.compactMap { (axUiElement, wid, axTitle, isFullscreen, isMinimized, position, size) in
|
||||||
if (Windows.list.firstIndex { $0.isEqualRobust(axUiElement, wid) }) == nil {
|
if (Windows.list.firstIndex { $0.isEqualRobust(axUiElement, wid) }) == nil {
|
||||||
@@ -118,18 +150,6 @@ class Application: NSObject {
|
|||||||
return windows
|
return windows
|
||||||
}
|
}
|
||||||
|
|
||||||
func addWindowslessAppsIfNeeded() -> [Window]? {
|
|
||||||
if !Preferences.hideWindowlessApps &&
|
|
||||||
runningApplication.activationPolicy == .regular &&
|
|
||||||
!runningApplication.isTerminated &&
|
|
||||||
(Windows.list.firstIndex { $0.application.pid == pid }) == nil {
|
|
||||||
let window = Window(self)
|
|
||||||
Windows.appendAndUpdateFocus(window)
|
|
||||||
return [window]
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
private func observeEvents() {
|
private func observeEvents() {
|
||||||
guard let axObserver = axObserver else { return }
|
guard let axObserver = axObserver else { return }
|
||||||
for notification in [
|
for notification in [
|
||||||
|
|||||||
@@ -138,25 +138,6 @@ class Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func quitApp() {
|
|
||||||
// prevent users from quitting Finder
|
|
||||||
if application.runningApplication.bundleIdentifier == "com.apple.finder" && !Preferences.finderShowsQuitMenuItem { return }
|
|
||||||
BackgroundWork.accessibilityCommandsQueue.asyncWithCap { [weak self] in
|
|
||||||
self?.application.runningApplication.terminate()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func hideShowApp() {
|
|
||||||
BackgroundWork.accessibilityCommandsQueue.asyncWithCap { [weak self] in
|
|
||||||
guard let self = self else { return }
|
|
||||||
if self.application.runningApplication.isHidden {
|
|
||||||
self.application.runningApplication.unhide()
|
|
||||||
} else {
|
|
||||||
self.application.runningApplication.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func focus() {
|
func focus() {
|
||||||
if isWindowlessApp || cgWindowId == nil {
|
if isWindowlessApp || cgWindowId == nil {
|
||||||
if let bundleID = application.runningApplication.bundleIdentifier {
|
if let bundleID = application.runningApplication.bundleIdentifier {
|
||||||
|
|||||||
+2
-2
@@ -133,11 +133,11 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func quitSelectedApp() {
|
func quitSelectedApp() {
|
||||||
Windows.focusedWindow()?.quitApp()
|
Windows.focusedWindow()?.application.quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideShowSelectedApp() {
|
func hideShowSelectedApp() {
|
||||||
Windows.focusedWindow()?.hideShowApp()
|
Windows.focusedWindow()?.application.hideOrShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func focusTarget() {
|
func focusTarget() {
|
||||||
|
|||||||
Reference in new issue
Block a user