From 2ce8d92cb629ba44d82b177490d51056c3e82384 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Mon, 10 Jun 2019 11:11:27 +0200 Subject: [PATCH] first run checkbox value --- Stats/AppDelegate.swift | 8 +++++++- Stats/MenuBar.swift | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Stats/AppDelegate.swift b/Stats/AppDelegate.swift index 16cb9d44..ab732e83 100755 --- a/Stats/AppDelegate.swift +++ b/Stats/AppDelegate.swift @@ -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!) } diff --git a/Stats/MenuBar.swift b/Stats/MenuBar.swift index 783598bd..a367a5ab 100644 --- a/Stats/MenuBar.swift +++ b/Stats/MenuBar.swift @@ -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)