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

Sync status item removal by dragging with settings #1057

Merged
merged 1 commit into from
Jan 28, 2023
Merged
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
4 changes: 4 additions & 0 deletions Rectangle/PrefsWindow/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class SettingsViewController: NSViewController {
self.initializeTodoModeSettings()
self.initializeToggles()
})

Notification.Name.menuBarIconHidden.onPost(using: {_ in
self.hideMenuBarIconCheckbox.state = .on
})
}

func initializeTodoModeSettings() {
Expand Down
10 changes: 8 additions & 2 deletions Rectangle/RectangleStatusItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RectangleStatusItem {
nsStatusItem?.menu = statusMenu
}
}
private var isVisibleObserver: NSKeyValueObservation?

private init() {}

Expand All @@ -42,9 +43,14 @@ class RectangleStatusItem {
nsStatusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
nsStatusItem?.menu = self.statusMenu
nsStatusItem?.button?.image = NSImage(named: "StatusTemplate")
if #available(OSX 10.12, *) {
nsStatusItem?.behavior = .removalAllowed
nsStatusItem?.behavior = .removalAllowed
isVisibleObserver = nsStatusItem?.observe(\.isVisible, options: [.old, .new]) { nsStatusItem, change in
if change.oldValue == true && change.newValue == false {
Notification.Name.menuBarIconHidden.post()
Defaults.hideMenuBarIcon.enabled = true
}
}
nsStatusItem?.isVisible = true
}

private func remove() {
Expand Down
1 change: 1 addition & 0 deletions Rectangle/Utilities/NotificationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension Notification.Name {
static let todoMenuToggled = Notification.Name("todoMenuToggled")
static let appWillBecomeActive = Notification.Name("appWillBecomeActive")
static let missionControlDragging = Notification.Name("missionControlDragging")
static let menuBarIconHidden = Notification.Name("menuBarIconHidden")

func post(
center: NotificationCenter = NotificationCenter.default,
Expand Down