From 6eed7beab1f9134966d43e44055e2ec42256c001 Mon Sep 17 00:00:00 2001 From: ShlomoCode <78599753+ShlomoCode@users.noreply.github.com> Date: Wed, 26 Jun 2024 01:02:31 +0300 Subject: [PATCH] Refactor: get bundle url directly using NSWorkspace.shared.urlForApplication --- DockDoor/Utilities/WindowUtil.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/DockDoor/Utilities/WindowUtil.swift b/DockDoor/Utilities/WindowUtil.swift index 04960060..b50e9fe9 100644 --- a/DockDoor/Utilities/WindowUtil.swift +++ b/DockDoor/Utilities/WindowUtil.swift @@ -241,8 +241,8 @@ struct WindowUtil { /// Retrieves the active windows for a given application name. static func activeWindows(for applicationName: String) async throws -> [WindowInfo] { - func getNonLocalizedAppName(for app: NSRunningApplication) -> String? { - guard let bundleURL = app.bundleURL else { + func getNonLocalizedAppName(forBundleIdentifier bundleIdentifier: String) -> String? { + guard let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) else { return nil } @@ -259,8 +259,7 @@ struct WindowUtil { for window in content.windows { if let app = window.owningApplication, - let tempApp = NSRunningApplication.runningApplications(withBundleIdentifier: app.bundleIdentifier).first, - let nonLocalName = getNonLocalizedAppName(for: tempApp){ + let nonLocalName = getNonLocalizedAppName(forBundleIdentifier: app.bundleIdentifier) { // Collect potential matches if applicationName.contains(app.applicationName) {