mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
first run checkbox value
This commit is contained in:
@@ -34,7 +34,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
let runningApps = NSWorkspace.shared.runningApplications
|
||||
let isRunning = !runningApps.filter { $0.bundleIdentifier == launcherAppId }.isEmpty
|
||||
|
||||
SMLoginItemSetEnabled(launcherAppId as CFString, true)
|
||||
if defaults.object(forKey: "runAtLogin") != nil {
|
||||
SMLoginItemSetEnabled(launcherAppId as CFString, defaults.bool(forKey: "runAtLogin"))
|
||||
} else {
|
||||
SMLoginItemSetEnabled(launcherAppId as CFString, true)
|
||||
self.defaults.set(true, forKey: "runAtLogin")
|
||||
}
|
||||
|
||||
if isRunning {
|
||||
DistributedNotificationCenter.default().post(name: .killLauncher, object: Bundle.main.bundleIdentifier!)
|
||||
}
|
||||
|
||||
@@ -51,12 +51,12 @@ class MenuBar {
|
||||
let preferencesMenu = NSMenu()
|
||||
|
||||
let colorStatus = NSMenuItem(title: "Colors", action: #selector(toggleMenu), keyEquivalent: "")
|
||||
colorStatus.state = defaults.object(forKey: "colors") != nil && !defaults.bool(forKey: "colors") ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
colorStatus.state = defaults.bool(forKey: "colors") ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
colorStatus.target = self
|
||||
preferencesMenu.addItem(colorStatus)
|
||||
|
||||
let runAtLogin = NSMenuItem(title: "Run at login", action: #selector(toggleMenu), keyEquivalent: "")
|
||||
runAtLogin.state = defaults.object(forKey: "runAtLogin") != nil && !defaults.bool(forKey: "runAtLogin") ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
runAtLogin.state = defaults.bool(forKey: "runAtLogin") || defaults.object(forKey: "runAtLogin") == nil ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
runAtLogin.target = self
|
||||
preferencesMenu.addItem(runAtLogin)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user