From 5fff6a9b8d58d8cb2a9076e1dc335459afd95e39 Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 10:46:16 +0100 Subject: [PATCH 01/18] Add support for showing Dock Icon and Menu --- Dozer/DozerIcons.swift | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 9a6e37e..0b8c75a 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -125,8 +125,10 @@ public final class DozerIcons { public func toggle() { if get(dozerIcon: .normalLeft).isShown { + hideIconAndMenu() hide() } else { + showIconAndMenu() show() } } @@ -139,6 +141,15 @@ public final class DozerIcons { } } + public func showIconAndMenu() { + _ = DozerIcons.toggleDockIcon(showIcon: true) + NSApp.activate(ignoringOtherApps: true) + } + + public func hideIconAndMenu() { + _ = DozerIcons.toggleDockIcon(showIcon: false) + } + /// Force show all Dozer status bar icons public func showAll() { perform(action: .show, statusIcon: .remove) @@ -148,6 +159,7 @@ public final class DozerIcons { } public func handleOptionClick() { + showIconAndMenu() if get(dozerIcon: .normalLeft).isShown { DozerIcons.shared.perform( action: .toggle, @@ -188,6 +200,7 @@ public final class DozerIcons { return } + hideIconAndMenu() DozerIcons.shared.hide() } @@ -255,6 +268,17 @@ public final class DozerIcons { } } + /// hide and show dock icon and thus its menu bar + public class func toggleDockIcon(showIcon state: Bool) -> Bool { + var result: Bool + if state { + result = NSApp.setActivationPolicy(NSApplication.ActivationPolicy.regular) + } else { + result = NSApp.setActivationPolicy(NSApplication.ActivationPolicy.accessory) + } + return result + } + /// Determines if the user is interacting with the status bar based on level, owner and y-coordinate /// /// - Returns: Returns whether the user is interacting with the status bar or not From 9b84b474e7dd7ac70fbf57241c4db46183583e4b Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 11:20:45 +0100 Subject: [PATCH 02/18] user preference for showIconAndMenu --- Dozer/Constants.swift | 1 + Dozer/DozerIcons.swift | 16 ++++++-- Dozer/ViewControllers/GeneralVC.swift | 6 +++ Dozer/XIB/General.xib | 59 ++++++++++++++++++--------- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/Dozer/Constants.swift b/Dozer/Constants.swift index 83d15dd..43346e5 100644 --- a/Dozer/Constants.swift +++ b/Dozer/Constants.swift @@ -13,6 +13,7 @@ extension Defaults.Keys { static let hideAfterDelay: Defaults.Key = Key("hideAfterDelay", default: 10) static let noIconMode: Defaults.Key = Key("noIconMode", default: false) static let removeDozerIconEnabled: Defaults.Key = Key("removeStatusIconEnabled", default: false) + static let showIconAndMenuEnabled: Defaults.Key = Key("showIconAndMenuEnabled", default: false) static let iconSize: Defaults.Key = Key("fontSize", default: 10) static let buttonPadding: Defaults.Key = Key("buttonPadding", default: 25) static let animationEnabled: Defaults.Key = Key("animationEnabeld", default: false) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 0b8c75a..b405aa9 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -86,6 +86,12 @@ public final class DozerIcons { } } + public var enableIconAndMenu: Bool = Defaults[.showIconAndMenuEnabled] { + didSet { + Defaults[.showIconAndMenuEnabled] = self.enableIconAndMenu + } + } + public var iconFontSize: Int = Defaults[.iconSize] { didSet { Defaults[.iconSize] = self.iconFontSize @@ -142,12 +148,16 @@ public final class DozerIcons { } public func showIconAndMenu() { - _ = DozerIcons.toggleDockIcon(showIcon: true) - NSApp.activate(ignoringOtherApps: true) + if Defaults[.showIconAndMenuEnabled] { + _ = DozerIcons.toggleDockIcon(showIcon: true) + NSApp.activate(ignoringOtherApps: true) + } } public func hideIconAndMenu() { - _ = DozerIcons.toggleDockIcon(showIcon: false) + if Defaults[.showIconAndMenuEnabled] { + _ = DozerIcons.toggleDockIcon(showIcon: false) + } } /// Force show all Dozer status bar icons diff --git a/Dozer/ViewControllers/GeneralVC.swift b/Dozer/ViewControllers/GeneralVC.swift index 65b0236..ba82fef 100644 --- a/Dozer/ViewControllers/GeneralVC.swift +++ b/Dozer/ViewControllers/GeneralVC.swift @@ -25,6 +25,7 @@ final class General: NSViewController, PreferencePane { @IBOutlet private var HideStatusBarIconsSecondsPopUpButton: NSPopUpButton! @IBOutlet private var HideBothDozerIconsCheckbox: NSButton! @IBOutlet private var EnableRemoveDozerIconCheckbox: NSButton! + @IBOutlet private var ShowIconAndMenuCheckbox: NSButton! @IBOutlet private var FontSizePopUpButton: NSPopUpButton! @IBOutlet private var ButtonPaddingPopUpButton: NSPopUpButton! @IBOutlet private var ToggleMenuItemsView: MASShortcutView! @@ -45,6 +46,7 @@ final class General: NSViewController, PreferencePane { HideStatusBarIconsAfterDelayCheckbox.isChecked = Defaults[.hideAfterDelayEnabled] HideBothDozerIconsCheckbox.isChecked = Defaults[.noIconMode] EnableRemoveDozerIconCheckbox.isChecked = Defaults[.removeDozerIconEnabled] + ShowIconAndMenuCheckbox.isChecked = Defaults[.showIconAndMenuEnabled] HideStatusBarIconsSecondsPopUpButton.selectItem(withTitle: "\(Int(Defaults[.hideAfterDelay])) seconds") FontSizePopUpButton.selectItem(withTitle: "\(Int(Defaults[.iconSize])) px") ButtonPaddingPopUpButton.selectItem(withTitle: "\(Int(Defaults[.buttonPadding])) px") @@ -86,6 +88,10 @@ final class General: NSViewController, PreferencePane { DozerIcons.shared.hideBothDozerIcons = HideBothDozerIconsCheckbox.isChecked } + @IBAction private func showIconAndMenuClicked(_ sender: NSButton) { + DozerIcons.shared.enableIconAndMenu = ShowIconAndMenuCheckbox.isChecked + } + @IBAction private func fontSizeChanged(_ sender: NSPopUpButton) { DozerIcons.shared.iconFontSize = FontSizePopUpButton.selectedTag() } diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 931cb64..9851aae 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -1,8 +1,8 @@ - + - + @@ -17,6 +17,7 @@ + @@ -24,10 +25,10 @@ - + - + @@ -47,7 +48,7 @@ + + + + + + + + + + - + @@ -89,7 +110,7 @@ - + @@ -112,7 +133,7 @@ - + - + @@ -175,7 +196,7 @@ - + @@ -197,7 +218,7 @@ - + @@ -215,7 +236,7 @@ - + @@ -226,9 +247,9 @@ - + - + From 19fc8ce2a49551e1047b3128e8c8b00d8a63dc39 Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 11:38:49 +0100 Subject: [PATCH 03/18] change "status bar" references to "menu bar" --- Dozer/DozerIcons.swift | 12 +-- Dozer/XIB/General.xib | 206 +++++++++++++++++++++-------------------- 2 files changed, 111 insertions(+), 107 deletions(-) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index b405aa9..3249ccd 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -160,7 +160,7 @@ public final class DozerIcons { } } - /// Force show all Dozer status bar icons + /// Force show all Dozer icons public func showAll() { perform(action: .show, statusIcon: .remove) perform(action: .show, statusIcon: .normalLeft) @@ -204,7 +204,7 @@ public final class DozerIcons { return } - // don't hide on user interaction with status bar + // don't hide on user interaction with menu bar guard !isUserInteractingWithStatusBar() else { resetTimer() return @@ -253,7 +253,7 @@ public final class DozerIcons { } } - /// Will crash if trying to get ´DozerIcon´ which does not exist in the status bar + /// Will crash if trying to get ´DozerIcon´ which does not exist in the menu bar private func get(dozerIcon: DozerIcon) -> HelperstatusIcon { var normalStatusIconsXPosition: [CGFloat] = [] for statusIcon in dozerIcons where statusIcon.type == .normal { @@ -289,9 +289,9 @@ public final class DozerIcons { return result } - /// Determines if the user is interacting with the status bar based on level, owner and y-coordinate + /// Determines if the user is interacting with the menu bar based on level, owner and y-coordinate /// - /// - Returns: Returns whether the user is interacting with the status bar or not + /// - Returns: Returns whether the user is interacting with the menu bar or not private func isUserInteractingWithStatusBar() -> Bool { let windowListType = CGWindowListOption.optionOnScreenOnly guard let windowInfoList = CGWindowListCopyWindowInfo(windowListType, kCGNullWindowID) as NSArray? as? [[String: AnyObject]] else { @@ -301,7 +301,7 @@ public final class DozerIcons { for windowInfo in windowInfoList { guard let window = Window(windowInfo), - // If the preferences window are close to the status bar it won't auto hide + // If the preferences window are close to the menu bar it won't auto hide window.owner != "Dozer" else { continue } diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 9851aae..1ffb441 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -25,10 +25,10 @@ - + - - - - - - - - - - + + + + - - - + + - + + + + + + + + + + + + + + + + + + + + + + - - - + + - + - - - - - - - - - - + + - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - + @@ -213,8 +191,17 @@ + + + + + + + + + - + @@ -235,21 +222,38 @@ - - + + + + + + + + + + + - - - + + + + + + + + + + + - - + + - + From 163f02aebea3339c100eecf2ef327f493a347e26 Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 11:39:13 +0100 Subject: [PATCH 04/18] fix issue with timer not resetting on option-click --- Dozer/DozerIcons.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 3249ccd..4f80028 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -175,7 +175,6 @@ public final class DozerIcons { action: .toggle, statusIcon: .remove ) - resetTimer() } else { DozerIcons.shared.perform( action: .show, @@ -186,6 +185,7 @@ public final class DozerIcons { statusIcon: .remove ) } + resetTimer() } // MARK: Show/hide lifecycle From c534d69165e72c2093e1784d2456672a7622496b Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 11:47:12 +0100 Subject: [PATCH 05/18] prefs UI tweaks --- Dozer/XIB/General.xib | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 1ffb441..7121218 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -25,10 +25,10 @@ - + - + - + @@ -97,7 +97,7 @@ - + @@ -106,7 +106,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -166,11 +166,11 @@ - + - + @@ -201,7 +201,7 @@ - + @@ -223,20 +223,20 @@ - + - + - + - + @@ -251,7 +251,7 @@ - + From 4395c31a1640eb989775c8f8cfa083a2c756f98b Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 11:49:21 +0100 Subject: [PATCH 06/18] another UI tweaks --- Dozer/XIB/General.xib | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 7121218..525be70 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -170,7 +170,7 @@ - + @@ -223,7 +223,7 @@ - + @@ -240,7 +240,7 @@ - + From aedd6ffe96dd09843f03afaeaec1726ddbeb2a9b Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sat, 4 Jul 2020 11:55:36 +0100 Subject: [PATCH 07/18] typo --- Dozer/XIB/General.xib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 525be70..446584e 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -148,7 +148,7 @@ - + @@ -137,7 +137,7 @@ - + @@ -146,9 +146,9 @@ - + - + - + - + @@ -192,7 +192,7 @@ - + @@ -201,7 +201,7 @@ - + @@ -223,7 +223,7 @@ - + @@ -232,7 +232,7 @@ - + From e4aad758abd6af790b859245fbd496c8bb5fc5e4 Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Sun, 5 Jul 2020 17:19:03 +0100 Subject: [PATCH 12/18] "full width of screen" rather than "full screen width" clarification --- Dozer/XIB/General.xib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 30519f7..32e0667 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -146,9 +146,9 @@ @@ -50,6 +53,8 @@ + q + From 1c8e5a5dd04dd9b1fb02581d1e28200ef5a21753 Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Thu, 9 Jul 2020 15:02:05 +0100 Subject: [PATCH 15/18] Be nice and refocus previous app --- Dozer/DozerIcons.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 5d4c18a..1aa8957 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -10,6 +10,7 @@ public final class DozerIcons { private var dozerIcons: [HelperstatusIcon] = [] private var timerToCheckUserInteraction = Timer() private var timerToHideDozerIcons = Timer() + private var previousApp = NSRunningApplication() private init() { dozerIcons.append(NormalStatusIcon()) @@ -153,6 +154,9 @@ public final class DozerIcons { } public func showIconAndMenu() { + if NSWorkspace.shared.frontmostApplication?.bundleIdentifier != "com.mortennn.Dozer" { + previousApp = NSWorkspace.shared.frontmostApplication! + } if Defaults[.showIconAndMenuEnabled] { _ = DozerIcons.toggleDockIcon(showIcon: true) NSApp.activate(ignoringOtherApps: true) @@ -162,6 +166,10 @@ public final class DozerIcons { public func hideIconAndMenu() { if Defaults[.showIconAndMenuEnabled] { _ = DozerIcons.toggleDockIcon(showIcon: false) + if NSWorkspace.shared.frontmostApplication?.bundleIdentifier == "com.mortennn.Dozer" { + previousApp.activate() + } + NSApp.hide(self) } } From dbc0ba7773f624c91516001264bda945fe7421ed Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Thu, 9 Jul 2020 15:04:07 +0100 Subject: [PATCH 16/18] Remove stray timer --- Dozer/DozerIcons.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 1aa8957..fa258ff 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -203,7 +203,7 @@ public final class DozerIcons { // MARK: Show/hide lifecycle private func didShowStatusBarIcons() { - startTimer() + //startTimer() startUserInteractionTimer() } From 8d95f525cb473f08bd5931c3893ec6d229e07abd Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Thu, 9 Jul 2020 16:57:41 +0100 Subject: [PATCH 17/18] removed uneccesary NSApp.hide(self) --- Dozer/DozerIcons.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index fa258ff..1f4ea6b 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -169,7 +169,6 @@ public final class DozerIcons { if NSWorkspace.shared.frontmostApplication?.bundleIdentifier == "com.mortennn.Dozer" { previousApp.activate() } - NSApp.hide(self) } } From a2f4a32622d6258268d0b7333786e1f4213b5fcc Mon Sep 17 00:00:00 2001 From: Matt Sephton Date: Thu, 9 Jul 2020 17:24:47 +0100 Subject: [PATCH 18/18] Don't hard code bundle identifier --- Dozer/Constants.swift | 2 +- Dozer/DozerIcons.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dozer/Constants.swift b/Dozer/Constants.swift index 43346e5..53c893a 100644 --- a/Dozer/Constants.swift +++ b/Dozer/Constants.swift @@ -35,7 +35,7 @@ extension PreferencePaneIdentifier { } struct AppInfo { - static let bundleIdentifier: String = "com.mortennn.Dozer" + static let bundleIdentifier: String = Bundle.main.bundleIdentifier! static var releaseVersionNumber: String? { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String } diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 1f4ea6b..df8233e 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -154,7 +154,7 @@ public final class DozerIcons { } public func showIconAndMenu() { - if NSWorkspace.shared.frontmostApplication?.bundleIdentifier != "com.mortennn.Dozer" { + if NSWorkspace.shared.frontmostApplication?.bundleIdentifier != AppInfo.bundleIdentifier { previousApp = NSWorkspace.shared.frontmostApplication! } if Defaults[.showIconAndMenuEnabled] { @@ -166,7 +166,7 @@ public final class DozerIcons { public func hideIconAndMenu() { if Defaults[.showIconAndMenuEnabled] { _ = DozerIcons.toggleDockIcon(showIcon: false) - if NSWorkspace.shared.frontmostApplication?.bundleIdentifier == "com.mortennn.Dozer" { + if NSWorkspace.shared.frontmostApplication?.bundleIdentifier == AppInfo.bundleIdentifier { previousApp.activate() } }