Skip to content

Commit bf0b237

Browse files
committed
Prevent multiple instances from running simultaneously
Exit early if another instance with the same bundle ID is already running.
1 parent a1ec4d4 commit bf0b237

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Sources/UsageBar/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ extension AppDelegate {
436436

437437
// MARK: - Entry Point
438438

439+
// Prevent multiple instances
440+
let runningInstances = NSRunningApplication.runningApplications(withBundleIdentifier: "com.usagebar")
441+
if runningInstances.count > 1 {
442+
exit(0)
443+
}
444+
439445
let app = NSApplication.shared
440446
let delegate = AppDelegate()
441447
app.delegate = delegate

0 commit comments

Comments
 (0)