Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to change right icon to arrow #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dozer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
Fabric.with([Crashlytics.self])
#endif

MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: UserDefaultKeys.Shortcuts.ToggleMenuItems) { [unowned self] in
MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: UserDefaultKeys.Shortcuts.ToggleMenuItems) { () in
Copy link

@emrcftci emrcftci Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you are not using _ instead of ()?

DozerIcons.shared.toggle()
}

Expand Down
1 change: 1 addition & 0 deletions Dozer/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extension Defaults.Keys {
static let hideAfterDelayEnabled: Defaults.Key<Bool> = Key<Bool>("hideAfterDelayEnabled", default: false)
static let hideAfterDelay: Defaults.Key<TimeInterval> = Key<TimeInterval>("hideAfterDelay", default: 10)
static let noIconMode: Defaults.Key<Bool> = Key<Bool>("noIconMode", default: false)
static let rightIconArrow: Defaults.Key<Bool> = Key<Bool>("rightIconArrow", default: false)
static let removeDozerIconEnabled: Defaults.Key<Bool> = Key<Bool>("removeStatusIconEnabled", default: false)
static let animationEnabled: Defaults.Key<Bool> = Key<Bool>("animationEnabeld", default: false)
}
Expand Down
34 changes: 33 additions & 1 deletion Dozer/DozerIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public final class DozerIcons {
dozerIcons.append(NormalStatusIcon())

if !hideBothDozerIcons {
dozerIcons.append(NormalStatusIcon())
let rightIcon = NormalStatusIcon()
if rightIconAsArrow {
rightIcon.statusIcon.image = NSImage(named: (hideStatusBarIconsAtLaunch) ? NSImage.goLeftTemplateName : NSImage.goRightTemplateName)
}
dozerIcons.append(rightIcon)
}

if enableRemoveDozerIcon {
Expand Down Expand Up @@ -65,13 +69,30 @@ public final class DozerIcons {
didSet {
defaults[.noIconMode] = self.hideBothDozerIcons
if hideBothDozerIcons {
let leftDozerIcon = get(dozerIcon: .normalLeft)
if rightIconAsArrow {
leftDozerIcon.statusIcon.image = NSImage(named: NSImage.goRightTemplateName)
}
let rightDozerIconXPos = get(dozerIcon: .normalRight).xPositionOnScreen
dozerIcons.removeAll(where: { $0.xPositionOnScreen == rightDozerIconXPos })
} else {
dozerIcons.append(NormalStatusIcon())
}
}
}

public var rightIconAsArrow: Bool = defaults[.rightIconArrow] {
didSet {
defaults[.rightIconArrow] = self.rightIconAsArrow
let rightIcon = get(dozerIcon: .normalRight)
if rightIconAsArrow {
let leftIcon = get(dozerIcon: .normalLeft)
rightIcon.statusIcon.image = (leftIcon.isShown) ? NSImage(named: NSImage.goRightTemplateName) : NSImage(named: NSImage.goLeftTemplateName)
} else {
rightIcon.setIcon()
}
}
}

public var enableRemoveDozerIcon: Bool = defaults[.removeDozerIconEnabled] {
didSet {
Expand All @@ -91,15 +112,26 @@ public final class DozerIcons {
perform(action: .hide, statusIcon: .normalLeft)
if defaults[.noIconMode] {
perform(action: .hide, statusIcon: .normalRight)
} else if rightIconAsArrow {
let rightIcon = get(dozerIcon: .normalRight)
rightIcon.statusIcon.image = NSImage(named: NSImage.goLeftTemplateName)
}
didHideStatusBarIcons()
}

public func show() {
perform(action: .hide, statusIcon: .remove)
perform(action: .show, statusIcon: .normalLeft)
let leftIcon = get(dozerIcon: .normalLeft)
if leftIcon.statusIcon.image?.name() == NSImage(named: NSImage.goRightTemplateName)?.name() ||
leftIcon.statusIcon.image?.name() == NSImage(named: NSImage.goLeftTemplateName)?.name() {
leftIcon.setIcon()
}
if defaults[.noIconMode] {
perform(action: .show, statusIcon: .normalRight)
} else if rightIconAsArrow {
let rightIcon = get(dozerIcon: .normalRight)
rightIcon.statusIcon.image = NSImage(named: NSImage.goRightTemplateName)
}
didShowStatusBarIcons()
}
Expand Down
2 changes: 1 addition & 1 deletion Dozer/Other/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>4.1.0</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
16 changes: 16 additions & 0 deletions Dozer/ViewControllers/GeneralVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class General: NSViewController, PreferencePane {
@IBOutlet private var HideStatusBarIconsAtLaunchCheckbox: NSButton!
@IBOutlet private var HideStatusBarIconsAfterDelayCheckbox: NSButton!
@IBOutlet private var HideBothDozerIconsCheckbox: NSButton!
@IBOutlet private var VisualizeRightAsArrowCheckbox: NSButton!
@IBOutlet private var EnableRemoveDozerIconCheckbox: NSButton!
@IBOutlet private var ToggleMenuItemsView: MASShortcutView!

Expand All @@ -43,7 +44,9 @@ final class General: NSViewController, PreferencePane {
HideStatusBarIconsAtLaunchCheckbox.isChecked = defaults[.hideAtLaunchEnabled]
HideStatusBarIconsAfterDelayCheckbox.isChecked = defaults[.hideAfterDelayEnabled]
HideBothDozerIconsCheckbox.isChecked = defaults[.noIconMode]
VisualizeRightAsArrowCheckbox.isChecked = defaults[.rightIconArrow]
EnableRemoveDozerIconCheckbox.isChecked = defaults[.removeDozerIconEnabled]
configureEnabledRightIconAsArrowCheckbox()

ToggleMenuItemsView.associatedUserDefaultsKey = UserDefaultKeys.Shortcuts.ToggleMenuItems
view.addSubview(ToggleMenuItemsView)
Expand Down Expand Up @@ -75,9 +78,22 @@ final class General: NSViewController, PreferencePane {

@IBAction private func hideBothDozerIconsClicked(_ sender: NSButton) {
DozerIcons.shared.hideBothDozerIcons = HideBothDozerIconsCheckbox.isChecked
configureEnabledRightIconAsArrowCheckbox()
}

@IBAction private func visualizeRightAsArrowClicked(_ sender: NSButton) {
DozerIcons.shared.rightIconAsArrow = VisualizeRightAsArrowCheckbox.isChecked
}

@IBAction private func enableRemoveDozerIconClicked(_ sender: NSButton) {
DozerIcons.shared.enableRemoveDozerIcon = EnableRemoveDozerIconCheckbox.isChecked
}

private func configureEnabledRightIconAsArrowCheckbox() {
if HideBothDozerIconsCheckbox.isChecked {
VisualizeRightAsArrowCheckbox.isChecked = false
DozerIcons.shared.rightIconAsArrow = VisualizeRightAsArrowCheckbox.isChecked
}
VisualizeRightAsArrowCheckbox.isEnabled = !HideBothDozerIconsCheckbox.isChecked
}
}
Loading