diff --git a/Dozer/AppDelegate.swift b/Dozer/AppDelegate.swift index 5c98e86..2a994bc 100755 --- a/Dozer/AppDelegate.swift +++ b/Dozer/AppDelegate.swift @@ -24,6 +24,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate { // Initalize Dozer Icons _ = DozerIcons.shared + if DozerIcons.shared.hideStatusBarIconsAtLaunch { + DozerIcons.shared.hide() + } } // Show all Dozer icons when opening Dozer from Finder etc. diff --git a/Dozer/Constants.swift b/Dozer/Constants.swift index 7fb485d..9ff3487 100644 --- a/Dozer/Constants.swift +++ b/Dozer/Constants.swift @@ -8,6 +8,7 @@ import Defaults extension Defaults.Keys { static let hideOnLogin: Defaults.Key = Key("hideOnLogin", default: false) + static let hideAtLaunchEnabled: Defaults.Key = Key("hideAtLaunchEnabled", default: false) static let hideAfterDelayEnabled: Defaults.Key = Key("hideAfterDelayEnabled", default: false) static let hideAfterDelay: Defaults.Key = Key("hideAfterDelay", default: 10) static let noIconMode: Defaults.Key = Key("noIconMode", default: false) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift old mode 100644 new mode 100755 index 8f357c9..07d802e --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -8,6 +8,7 @@ import Defaults public final class DozerIcons { static var shared = DozerIcons() private var dozerIcons: [HelperstatusIcon] = [] + private var timerToCheckUserInteraction = Timer() private var timerToHideDozerIcons = Timer() private init() { @@ -24,15 +25,31 @@ public final class DozerIcons { if hideStatusBarIconsAfterDelay { startTimer() } - - Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in + } + + private func startUserInteractionTimer() { + guard defaults[.hideAfterDelayEnabled] else { + stopUserInteractionTimer() + return + } + timerToCheckUserInteraction = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in if self.isUserInteractingWithStatusBar() { self.resetTimer() } } } + + private func stopUserInteractionTimer() { + timerToCheckUserInteraction.invalidate() + } // MARK: Observe changes to settings + public var hideStatusBarIconsAtLaunch: Bool = defaults[.hideAtLaunchEnabled] { + didSet { + defaults[.hideAtLaunchEnabled] = self.hideStatusBarIconsAtLaunch + } + } + public var hideStatusBarIconsAfterDelay: Bool = defaults[.hideAfterDelayEnabled] { didSet { defaults[.hideAfterDelayEnabled] = self.hideStatusBarIconsAfterDelay @@ -133,10 +150,12 @@ public final class DozerIcons { // MARK: Show/hide lifecycle private func didShowStatusBarIcons() { startTimer() + startUserInteractionTimer() } private func didHideStatusBarIcons() { stopTimer() + stopUserInteractionTimer() } private func willHideStatusBarIcons() { diff --git a/Dozer/ViewControllers/GeneralVC.swift b/Dozer/ViewControllers/GeneralVC.swift index 0637a68..101a779 100644 --- a/Dozer/ViewControllers/GeneralVC.swift +++ b/Dozer/ViewControllers/GeneralVC.swift @@ -22,6 +22,7 @@ final class General: NSViewController, PreferencePane { @IBOutlet private var LaunchAtLoginCheckbox: NSButton! @IBOutlet private var CheckForUpdatesCheckbox: NSButton! + @IBOutlet private var HideStatusBarIconsAtLaunchCheckbox: NSButton! @IBOutlet private var HideStatusBarIconsAfterDelayCheckbox: NSButton! @IBOutlet private var HideBothDozerIconsCheckbox: NSButton! @IBOutlet private var EnableRemoveDozerIconCheckbox: NSButton! @@ -39,6 +40,7 @@ final class General: NSViewController, PreferencePane { CheckForUpdatesCheckbox.isChecked = false } + HideStatusBarIconsAtLaunchCheckbox.isChecked = defaults[.hideAtLaunchEnabled] HideStatusBarIconsAfterDelayCheckbox.isChecked = defaults[.hideAfterDelayEnabled] HideBothDozerIconsCheckbox.isChecked = defaults[.noIconMode] EnableRemoveDozerIconCheckbox.isChecked = defaults[.removeDozerIconEnabled] @@ -62,6 +64,10 @@ final class General: NSViewController, PreferencePane { } SUUpdater.shared()!.automaticallyChecksForUpdates = CheckForUpdatesCheckbox.isChecked } + + @IBAction private func hideStatusBarIconsAtLaunchClicked(_ sender: NSButton) { + DozerIcons.shared.hideStatusBarIconsAtLaunch = HideStatusBarIconsAtLaunchCheckbox.isChecked + } @IBAction private func hideStatusBarIconsAfterDelayClicked(_ sender: NSButton) { DozerIcons.shared.hideStatusBarIconsAfterDelay = HideStatusBarIconsAfterDelayCheckbox.isChecked diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 5efbc46..5a450b1 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -11,6 +11,7 @@ + @@ -19,10 +20,10 @@ - + +