fix: focusing an app could open another version of it

This commit is contained in:
lwouis
2024-08-31 18:40:59 +02:00
parent eba5e422bf
commit 9d5f11aed5
+11 -8
View File
@@ -175,17 +175,20 @@ class Window {
}
func focus() {
if isWindowlessApp || cgWindowId == nil {
if let bundleID = application.runningApplication.bundleIdentifier {
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleID, additionalEventParamDescriptor: nil, launchIdentifier: nil)
} else {
application.runningApplication.activate(options: .activateIgnoringOtherApps)
}
Windows.previewFocusedWindowIfNeeded()
} else if let bundleID = application.runningApplication.bundleIdentifier, bundleID == App.id {
let bundleUrl = application.runningApplication.bundleURL
if bundleUrl == NSRunningApplication.current.bundleURL {
App.shared.activate(ignoringOtherApps: true)
App.app.window(withWindowNumber: Int(cgWindowId!))?.makeKeyAndOrderFront(nil)
Windows.previewFocusedWindowIfNeeded()
} else if isWindowlessApp || cgWindowId == nil {
if let bundleUrl = bundleUrl {
if (try? NSWorkspace.shared.launchApplication(at: bundleUrl, configuration: [:])) == nil {
application.runningApplication.activate(options: .activateAllWindows)
}
} else {
application.runningApplication.activate(options: .activateAllWindows)
}
Windows.previewFocusedWindowIfNeeded()
} else {
// macOS bug: when switching to a System Preferences window in another space, it switches to that space,
// but quickly switches back to another window in that space