diff --git a/Passepartout/App/AppDelegate.swift b/Passepartout/App/AppDelegate.swift index 1237bcf9..875b1aec 100644 --- a/Passepartout/App/AppDelegate.swift +++ b/Passepartout/App/AppDelegate.swift @@ -33,6 +33,9 @@ class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject { #if targetEnvironment(macCatalyst) mac.configure() mac.menu.install() + if ProcessInfo.processInfo.arguments.contains(Constants.Global.appArgumentBackground) { + mac.utils.sendAppToBackground() + } #endif return true } diff --git a/Passepartout/Constants.swift b/Passepartout/Constants.swift index bef96aa8..7c57c243 100644 --- a/Passepartout/Constants.swift +++ b/Passepartout/Constants.swift @@ -44,5 +44,7 @@ enum Constants { static let appBuildNumber = Int(Bundle.main.infoDictionary![kCFBundleVersionKey as String] as! String)! static let appVersionString = "\(appVersionNumber) (\(appBuildNumber))" + + static let appArgumentBackground = "-background" } } diff --git a/Passepartout/Launcher/AppDelegate.swift b/Passepartout/Launcher/AppDelegate.swift index a32d7fe9..49d60f84 100644 --- a/Passepartout/Launcher/AppDelegate.swift +++ b/Passepartout/Launcher/AppDelegate.swift @@ -37,18 +37,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject { func applicationDidFinishLaunching(_ notification: Notification) { guard !isAppRunning else { - NSApp.terminate(nil) + NSApp.terminate(self) return } - Task { - do { - let cfg = NSWorkspace.OpenConfiguration() - cfg.hides = true - try await NSWorkspace.shared.openApplication(at: appURL, configuration: cfg) - } catch { + let cfg = NSWorkspace.OpenConfiguration() + cfg.hides = true + cfg.arguments = [Constants.Global.appArgumentBackground] + NSWorkspace.shared.openApplication(at: appURL, configuration: cfg) { app, error in + if let error = error { NSLog("Unable to launch main app: \(error)") + return } - await NSApp.terminate(nil) + NSApp.terminate(self) } } } diff --git a/Passepartout/Launcher/Launcher.entitlements b/Passepartout/Launcher/Launcher.entitlements index f2ef3ae0..e89b7f32 100644 --- a/Passepartout/Launcher/Launcher.entitlements +++ b/Passepartout/Launcher/Launcher.entitlements @@ -2,9 +2,7 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.security.app-sandbox +