mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
fix(apple): Enforce single Firezone instance (#10313)
show an alert to the user and ask to quit previous Firezone instance manually before starting a new one. Resolves: #10295 --------- Signed-off-by: Mariusz Klochowicz <mariusz@klochowicz.com> Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
33a75f6fee
commit
963cc8ede0
@@ -73,6 +73,11 @@ struct FirezoneApp: App {
|
||||
var menuBar: MenuBar?
|
||||
var store: Store?
|
||||
|
||||
func applicationWillFinishLaunching(_ notification: Notification) {
|
||||
// Enforce single instance BEFORE the app fully launches
|
||||
enforceSingleInstance()
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_: Notification) {
|
||||
if let store {
|
||||
menuBar = MenuBar(store: store)
|
||||
@@ -86,6 +91,38 @@ struct FirezoneApp: App {
|
||||
maybeShowOutdatedAlert()
|
||||
}
|
||||
|
||||
private func enforceSingleInstance() {
|
||||
// Get the actual bundle identifier from the running app
|
||||
guard let bundleId = Bundle.main.bundleIdentifier else { return }
|
||||
|
||||
let runningApps = NSRunningApplication.runningApplications(
|
||||
withBundleIdentifier: bundleId
|
||||
)
|
||||
|
||||
guard runningApps.count > 1 else { return }
|
||||
|
||||
for app in runningApps where app != NSRunningApplication.current {
|
||||
DispatchQueue.main.async {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Another Firezone Instance Detected"
|
||||
alert.informativeText = """
|
||||
Another instance of Firezone is already running. \
|
||||
Please quit the other instance from the menu bar to continue.
|
||||
|
||||
Location: \(app.bundleURL?.path ?? "Unknown")
|
||||
"""
|
||||
alert.alertStyle = .warning
|
||||
alert.addButton(withTitle: "OK")
|
||||
|
||||
// Show alert
|
||||
alert.runModal()
|
||||
|
||||
// Exit this instance since we can't terminate the other one
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func maybeShowOutdatedAlert() {
|
||||
let osVersion = ProcessInfo.processInfo.operatingSystemVersion
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ export default function Apple() {
|
||||
<Entries downloadLinks={downloadLinks} title="macOS / iOS">
|
||||
{/* When you cut a release, remove any solved issues from the "known issues" lists over in `client-apps`. This must not be done when the issue's PR merges. */}
|
||||
<Unreleased>
|
||||
<ChangeItem pull="10313">
|
||||
Fixes an issue where multiple concurrent Firezone macOS clients could
|
||||
run simultaneously. We now enforce a single instance of the client.
|
||||
</ChangeItem>
|
||||
<ChangeItem pull="10224">
|
||||
Fixes a minor DNS cache bug where newly-added DNS resources may not
|
||||
resolve for a few seconds after showing up in the Resource List.
|
||||
|
||||
Reference in New Issue
Block a user