feat: add preference to hide menubar icon (closes #103)

This commit is contained in:
Licardo authored and lwouis committed 2020-07-12 03:41:20 +09:00
1 parent b1477fc670
commit 663511754b
4 files changed
+41 -5

No files matched your search

+6
View File
@@ -127,6 +127,9 @@
/* No comment provided by engineer. */
"Quit app" = "Quit app";
/* No comment provided by engineer. */
"Quit" = "Quit";
/* No comment provided by engineer. */
"Rows of windows:" = "Rows of windows:";
@@ -184,6 +187,9 @@
/* No comment provided by engineer. */
"Start at login:" = "Start at login:";
/*No comment provided by engineer.*/
"Hide menubar icon:" = "Hide menubar icon:";
/* No comment provided by engineer. */
"Theme:" = "Theme:";
+2
View File
@@ -36,6 +36,7 @@ class Preferences {
"fadeOutAnimation": "false",
"hideSpaceNumberLabels": "false",
"startAtLogin": "true",
"hideMenubarIcon": "false"
]
// constant values
@@ -72,6 +73,7 @@ class Preferences {
static var fadeOutAnimation: Bool { defaults.bool("fadeOutAnimation") }
static var hideSpaceNumberLabels: Bool { defaults.bool("hideSpaceNumberLabels") }
static var startAtLogin: Bool { defaults.bool("startAtLogin") }
static var hideMenubarIcon: Bool { defaults.bool("hideMenubarIcon") }
// macro values
static var theme: ThemePreference { defaults.macroPref("theme", ThemePreference.allCases) }
+24 -3
View File
@@ -13,7 +13,7 @@ class App: NSApplication, NSApplicationDelegate {
static let repository = "https://github.com/lwouis/alt-tab-macos"
static var app: App!
static let shortcutMonitor = LocalShortcutMonitor()
var statusItem: NSStatusItem!
static var statusItem: NSStatusItem!
var thumbnailsPanel: ThumbnailsPanel!
var preferencesWindowController: PreferencesWindowController!
var feedbackWindow: FeedbackWindow?
@@ -40,7 +40,7 @@ class App: NSApplication, NSApplicationDelegate {
BackgroundWork.start()
Preferences.migratePreferences()
Preferences.registerDefaults()
statusItem = Menubar.make()
App.statusItem = Menubar.make()
loadMainMenuXib()
thumbnailsPanel = ThumbnailsPanel()
Spaces.initialDiscovery()
@@ -50,8 +50,19 @@ class App: NSApplication, NSApplicationDelegate {
// TODO: undeterministic; events in the queue may still be processing; good enough for now
DispatchQueue.main.async { () -> () in Windows.sortByLevel() }
preloadWindows()
#if DEBUG
showPreferencesPanel()
#endif
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
NSApp.activate(ignoringOtherApps: true)
showPreferencesPanel()
return true
}
// pre-load some windows so they are faster on first display
private func preloadWindows() {
thumbnailsPanel.orderFront(nil)
@@ -69,6 +80,16 @@ class App: NSApplication, NSApplicationDelegate {
// pre-load tabs so we can interact with them before the user opens the preferences window
tabs.forEach { (tab: NSViewController) in tab.loadView() }
preferencesWindowController = PreferencesWindowController(preferencePanes: tabs as! [PreferencePane])
let window = preferencesWindowController.window!
let quitButton = NSButton(title: NSLocalizedString("Quit", comment: ""), target: nil, action: #selector(NSApplication.terminate(_:)))
let titleBarView = window.standardWindowButton(.closeButton)!.superview!
titleBarView.addSubview(quitButton)
quitButton.translatesAutoresizingMaskIntoConstraints = false
let topConstraint = NSLayoutConstraint(item: quitButton, attribute: .top, relatedBy: .equal, toItem: titleBarView, attribute: .top, multiplier: 1, constant: 5)
let rightConstraint = NSLayoutConstraint(item: quitButton, attribute: .right, relatedBy: .equal, toItem: titleBarView, attribute: .right, multiplier: 1, constant: -10)
titleBarView.addConstraints([topConstraint, rightConstraint])
}
// keyboard shortcuts are broken without a menu. We generated the default menu from XCode and load it
@@ -26,6 +26,7 @@ class GeneralTab: NSViewController, PreferencePane {
override func loadView() {
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
let hideMenubarIcon = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Hide menubar icon:", comment: ""), "hideMenubarIcon", extraAction: hideMenubarIconCallback)
var holdShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hold", comment: ""), "holdShortcut", Preferences.holdShortcut, false, labelPosition: .leftWithoutSeparator)
holdShortcut.append(LabelAndControl.makeLabel(NSLocalizedString("then press:", comment: "")))
let nextWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Select next window", comment: ""), "nextWindowShortcut", Preferences.nextWindowShortcut, labelPosition: .right)
@@ -54,18 +55,20 @@ class GeneralTab: NSViewController, PreferencePane {
let grid = GridView([
startAtLogin,
hideMenubarIcon,
[holdAndPress, shortcuts],
[checkboxesExplanations, checkboxes],
[toShowExplanations, toShow],
])
grid.column(at: 0).xPlacement = .trailing
[1, 2, 3].forEach { grid.row(at: $0).topPadding = GridView.interPadding }
[2, 3, 4].forEach { grid.row(at: $0).topPadding = GridView.interPadding }
grid.fit()
GeneralTab.shortcutsDependentOnHoldShortcut.append(contentsOf: [enableArrows[0] as! NSControl] +
[nextWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut].map { $0[0] as! NSControl })
GeneralTab.arrowKeysEnabledCallback(enableArrows[0] as! NSControl)
startAtLoginCallback(startAtLogin[1] as! NSControl)
hideMenubarIconCallback(hideMenubarIcon[1] as! NSControl)
view = grid
}
@@ -150,4 +153,8 @@ class GeneralTab: NSViewController, PreferencePane {
let _ = LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst.takeRetainedValue(), nil, nil, itemUrl, nil, nil).takeRetainedValue()
}
}
}
private func hideMenubarIconCallback(_ sender: NSControl) {
App.statusItem.isVisible = (sender as! NSButton).state == .off
}
}