From 9d5f11aed554085a5031dc26825b7ea04ca2a634 Mon Sep 17 00:00:00 2001 From: lwouis Date: Sat, 31 Aug 2024 18:40:59 +0200 Subject: [PATCH] fix: focusing an app could open another version of it --- src/logic/Window.swift | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/logic/Window.swift b/src/logic/Window.swift index a91403a9..c46d8e51 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -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