From 2af315d7f8f535d70cfa89bbca70ebb1cc3e2223 Mon Sep 17 00:00:00 2001 From: Kofi Gumbs Date: Sun, 5 Mar 2023 23:38:24 -0500 Subject: [PATCH] Add keepOpen config, closes #73 --- Multi.app/Contents/Resources/preferences.html | 1 + README.md | 2 ++ Sources/Runtime/Browser+NSApplicationDelegate.swift | 2 +- Sources/Runtime/Config.swift | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Multi.app/Contents/Resources/preferences.html b/Multi.app/Contents/Resources/preferences.html index 1188fc4..6efe1ac 100644 --- a/Multi.app/Contents/Resources/preferences.html +++ b/Multi.app/Contents/Resources/preferences.html @@ -89,6 +89,7 @@

Configure your Multi }, tab.customCookies); }); validate(undefinedOr(boolean, config.windowed), `an OPTIONAL BOOLEAN at "windowed" field`); + validate(undefinedOr(boolean, config.keepOpenAfterWindowClosed), `an OPTIONAL BOOLEAN at "keepOpenAfterWindowClosed" field`); validate(undefinedOr(boolean, config.alwaysNotify), `an OPTIONAL BOOLEAN at "alwaysNotify" field`); validate(undefinedOr(boolean, config.alwaysOnTop), `an OPTIONAL BOOLEAN at "alwaysOnTop" field`); validate(undefinedOr(string, config.openNewWindowsWith), `an OPTIONAL STRING at "openNewWindowsWith" field`); diff --git a/README.md b/README.md index 1bd924a..9b9467c 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ The JSON configuration uses the following top-level fields: |------------------------------|---------------------------------------------------|----------------------------------------------------------------------| | `tabs` | Array (Required) | Titles and URLs of tabs for this app | | `windowed` | Boolean (Optional, default `false`) | Start the app with each tab in its own window | +| `keepOpenAfterWindowClosed` | Boolean (Optional, default `false`) | Prevents app from quitting when the last window is closed | | `alwaysNotify` | Boolean (Optional, default `false`) | Show macOS notifications even if your app is currently focused | | `alwaysOnTop` | Boolean (Optional, default `false`) | Position this app's window on top of all others | | `openNewWindowsWith` | String (Optional, macOS 10.15+) | Override system default browser for external links — value is a _bundle identifier_ like `com.apple.Safari`, `com.google.Chrome`, or `com.mozilla.firefox` | @@ -112,6 +113,7 @@ Here's a fancier example that uses the optional fields referenced above: } ], "windowed": true, + "keepOpenAfterWindowClosed": true, "alwaysNotify": true, "alwaysOnTop": true, "openNewWindowsWith": "com.apple.Safari", diff --git a/Sources/Runtime/Browser+NSApplicationDelegate.swift b/Sources/Runtime/Browser+NSApplicationDelegate.swift index dd7269e..64e66ba 100644 --- a/Sources/Runtime/Browser+NSApplicationDelegate.swift +++ b/Sources/Runtime/Browser+NSApplicationDelegate.swift @@ -6,6 +6,6 @@ extension Browser: NSApplicationDelegate { } public func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { - return true + return !Config.keepOpenAfterWindowClosed } } diff --git a/Sources/Runtime/Config.swift b/Sources/Runtime/Config.swift index ab71cb3..d966086 100644 --- a/Sources/Runtime/Config.swift +++ b/Sources/Runtime/Config.swift @@ -3,6 +3,7 @@ import AppKit struct Config { struct Schema: Decodable { let windowed: Bool? + let keepOpenAfterWindowClosed: Bool? let alwaysNotify: Bool? let alwaysOnTop: Bool? let openNewWindowsWith: String? @@ -41,6 +42,10 @@ struct Config { return schema?.windowed ?? false }() + static let keepOpenAfterWindowClosed: Bool = { + return schema?.keepOpenAfterWindowClosed ?? false + }() + static let alwaysNotify: Bool = { return schema?.alwaysNotify ?? false }()