macoc/Sources/CapswitchApp/AppDelegate.swift

25 lines
831 B
Swift

import AppKit
final class AppDelegate: NSObject, NSApplicationDelegate {
private var statusBarController: StatusBarController?
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.accessory)
// Only one process may own the global Caps -> F19 mapping.
if let bundleID = Bundle.main.bundleIdentifier,
NSRunningApplication.runningApplications(withBundleIdentifier: bundleID)
.contains(where: {
$0.processIdentifier != ProcessInfo.processInfo.processIdentifier
}) {
NSApp.terminate(nil)
return
}
statusBarController = StatusBarController()
}
func applicationWillTerminate(_ notification: Notification) {
statusBarController = nil
}
}