diff --git a/alt-tab-macos.xcodeproj/project.pbxproj b/alt-tab-macos.xcodeproj/project.pbxproj index 75dca5cb3..6b49f3eae 100644 --- a/alt-tab-macos.xcodeproj/project.pbxproj +++ b/alt-tab-macos.xcodeproj/project.pbxproj @@ -89,7 +89,7 @@ BF0C8203D0EFEDEED0F908E8 /* ScreensEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C822D3BEDAB1F1C9F775E /* ScreensEvents.swift */; }; BF0C820C6E89C2D90FA30A4B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8F67ABD271F26FA0EDEF /* Localizable.strings */; }; BF0C8224CFD1ED511F3F0063 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8D94228D90FE99D4A3C8 /* Localizable.strings */; }; - BF0C823630E3DEAC576FAFE6 /* menubar-1@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C88BF67CF4D71002A60EB /* menubar-1@2x.png */; }; + BF0C823630E3DEAC576FAFE6 /* menubar-0@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C88BF67CF4D71002A60EB /* menubar-0@2x.png */; }; BF0C8249228867A3188E13F3 /* SystemAppearanceEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C869E544F968051715452 /* SystemAppearanceEvents.swift */; }; BF0C827A169F0DE86C8F12AD /* SystemScrollerStyleEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8B5D1A9658E64F8ECB56 /* SystemScrollerStyleEvents.swift */; }; BF0C828D53D429C2B8B22391 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C883EBA8FDA9CB61C91FD /* Localizable.strings */; }; @@ -98,7 +98,7 @@ BF0C83578F7292F307E30751 /* PopupButtonLikeSystemSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8A479D2B7FB80531F037 /* PopupButtonLikeSystemSettings.swift */; }; BF0C8382435C0087E131BD83 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8A900DA32A7F62457CC2 /* InfoPlist.strings */; }; BF0C83AB0186CC48FADF66A7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C847B2D68EACFAC1B06D1 /* Localizable.strings */; }; - BF0C83E902F75A97E8FD374A /* menubar-2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8D3333653ACAEF730DD8 /* menubar-2@2x.png */; }; + BF0C83E902F75A97E8FD374A /* menubar-1@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8D3333653ACAEF730DD8 /* menubar-1@2x.png */; }; BF0C8406805BDEC5B69E8803 /* screen-recording@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8E25373671B528AD448D /* screen-recording@2x.png */; }; BF0C84D7DC2AC65BB1C111EB /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8349BA94516E8760BAFA /* Localizable.strings */; }; BF0C84E5AC1D423625ABF3E6 /* Mocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C829EAA93A4C4ADB42CF8 /* Mocks.swift */; }; @@ -147,7 +147,7 @@ BF0C8C7E96DB48120462DA00 /* TrafficLightButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8DF400A1AF64EB0CD0B3 /* TrafficLightButton.swift */; }; BF0C8C7F5F9EE501B240D2E3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8532DEDE7C1218B90444 /* Localizable.strings */; }; BF0C8C8E35FF49CAA4BF5FC4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8A970BD1CAD555F31EDA /* Localizable.strings */; }; - BF0C8C9CA44285E493918A74 /* menubar-3@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8E54658B4DAEA0528200 /* menubar-3@2x.png */; }; + BF0C8C9CA44285E493918A74 /* menubar-2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8E54658B4DAEA0528200 /* menubar-2@2x.png */; }; BF0C8CBF5B4EE15FDB53C94B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C861EE84489EF56879CBF /* InfoPlist.strings */; }; BF0C8CC5057406014FD612CC /* ATShortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8BA452332236D972C60E /* ATShortcut.swift */; }; BF0C8D1C57D74106018D073C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C87F5D4AD51D6950C98B0 /* InfoPlist.strings */; }; @@ -348,7 +348,7 @@ BF0C81BB57B297B2432C4824 /* test-release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "test-release.xcconfig"; sourceTree = ""; }; BF0C81D602ED642A48D50B78 /* notarytool */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = notarytool; sourceTree = ""; }; BF0C822D3BEDAB1F1C9F775E /* ScreensEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScreensEvents.swift; sourceTree = ""; }; - BF0C828AF7BCC4F47E70B28F /* menubar-2.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = "menubar-2.svg"; sourceTree = ""; }; + BF0C828AF7BCC4F47E70B28F /* menubar-1.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = "menubar-1.svg"; sourceTree = ""; }; BF0C829EAA93A4C4ADB42CF8 /* Mocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Mocks.swift; sourceTree = ""; }; BF0C82C381FCBCF8109735AC /* pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = pl; path = InfoPlist.strings; sourceTree = ""; }; BF0C82D44C2DFAA5D8F60394 /* sq */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sq; path = Localizable.strings; sourceTree = ""; }; @@ -384,7 +384,7 @@ BF0C87320241EAE01E38EF53 /* .periphery.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.yaml; path = .periphery.yml; sourceTree = ""; }; BF0C873357DBF7008830E73F /* xcbeautify */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = xcbeautify; sourceTree = ""; }; BF0C87897C24638DDE4A9889 /* app-icons-style.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "app-icons-style.jpg"; sourceTree = ""; }; - BF0C87B913292EE53EDE4220 /* menubar-1.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = "menubar-1.svg"; sourceTree = ""; }; + BF0C87B913292EE53EDE4220 /* menubar-0.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = "menubar-0.svg"; sourceTree = ""; }; BF0C87C0514B13DACB6E702B /* fa */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = fa; path = Localizable.strings; sourceTree = ""; }; BF0C87D65E0436CBC0EF29FA /* uz */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = uz; path = Localizable.strings; sourceTree = ""; }; BF0C87F376F3DC4C453878A6 /* th */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = th; path = Localizable.strings; sourceTree = ""; }; @@ -395,7 +395,7 @@ BF0C888D912E73D88919899A /* uk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = uk; path = Localizable.strings; sourceTree = ""; }; BF0C889529FF19620EDAC295 /* accessibility@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "accessibility@2x.png"; sourceTree = ""; }; BF0C8898ADB2A1B49312E87B /* cs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = cs; path = InfoPlist.strings; sourceTree = ""; }; - BF0C88BF67CF4D71002A60EB /* menubar-1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menubar-1@2x.png"; sourceTree = ""; }; + BF0C88BF67CF4D71002A60EB /* menubar-0@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menubar-0@2x.png"; sourceTree = ""; }; BF0C88C4940CA76FA801B881 /* preferences-appearance-details.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "preferences-appearance-details.jpg"; sourceTree = ""; }; BF0C890AF36F3EFD5CC4D114 /* bg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = bg; path = Localizable.strings; sourceTree = ""; }; BF0C89143F55C42D8A398C5A /* ku */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ku; path = Localizable.strings; sourceTree = ""; }; @@ -432,7 +432,7 @@ BF0C8C6995992F837A9A83A6 /* ca */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ca; path = InfoPlist.strings; sourceTree = ""; }; BF0C8CA36F8BD99BF38A45D0 /* bn */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = bn; path = InfoPlist.strings; sourceTree = ""; }; BF0C8CE7BBC3B9B0CEC008FF /* vi */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = vi; path = Localizable.strings; sourceTree = ""; }; - BF0C8D3333653ACAEF730DD8 /* menubar-2@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menubar-2@2x.png"; sourceTree = ""; }; + BF0C8D3333653ACAEF730DD8 /* menubar-1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menubar-1@2x.png"; sourceTree = ""; }; BF0C8D52C3D33B0669ECF996 /* ro */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ro; path = InfoPlist.strings; sourceTree = ""; }; BF0C8D57C86AF492D43A576D /* AppearanceTestable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppearanceTestable.swift; sourceTree = ""; }; BF0C8D606B53D315F2D9927B /* KeyRepeatTimer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyRepeatTimer.swift; sourceTree = ""; }; @@ -445,7 +445,7 @@ BF0C8E1FBCBC7B64C69D933C /* titles-style-full.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "titles-style-full.jpg"; sourceTree = ""; }; BF0C8E25373671B528AD448D /* screen-recording@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "screen-recording@2x.png"; sourceTree = ""; }; BF0C8E478D68ED85DAE6BF43 /* ga */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ga; path = InfoPlist.strings; sourceTree = ""; }; - BF0C8E54658B4DAEA0528200 /* menubar-3@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menubar-3@2x.png"; sourceTree = ""; }; + BF0C8E54658B4DAEA0528200 /* menubar-2@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menubar-2@2x.png"; sourceTree = ""; }; BF0C8E5D2BD5F7F93DF77DF5 /* sk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sk; path = InfoPlist.strings; sourceTree = ""; }; BF0C8E7B087DCC97A454C0AE /* uk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = uk; path = InfoPlist.strings; sourceTree = ""; }; BF0C8EAF02309B9C489E65F4 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -784,11 +784,11 @@ BF0C80536B40523C5DB23BE2 /* menubar */ = { isa = PBXGroup; children = ( - BF0C88BF67CF4D71002A60EB /* menubar-1@2x.png */, - BF0C8D3333653ACAEF730DD8 /* menubar-2@2x.png */, - BF0C828AF7BCC4F47E70B28F /* menubar-2.svg */, - BF0C8E54658B4DAEA0528200 /* menubar-3@2x.png */, - BF0C87B913292EE53EDE4220 /* menubar-1.svg */, + BF0C88BF67CF4D71002A60EB /* menubar-0@2x.png */, + BF0C8D3333653ACAEF730DD8 /* menubar-1@2x.png */, + BF0C828AF7BCC4F47E70B28F /* menubar-1.svg */, + BF0C8E54658B4DAEA0528200 /* menubar-2@2x.png */, + BF0C87B913292EE53EDE4220 /* menubar-0.svg */, ); path = menubar; sourceTree = ""; @@ -1934,9 +1934,9 @@ D04BAC23045A0A119B527DEB /* InfoPlist.strings in Resources */, D04BA328F7C85DD1A6C1C7ED /* Localizable.strings in Resources */, BF0C852D28E458CDD6FA3E44 /* app.icns in Resources */, - BF0C823630E3DEAC576FAFE6 /* menubar-1@2x.png in Resources */, - BF0C83E902F75A97E8FD374A /* menubar-2@2x.png in Resources */, - BF0C8C9CA44285E493918A74 /* menubar-3@2x.png in Resources */, + BF0C823630E3DEAC576FAFE6 /* menubar-0@2x.png in Resources */, + BF0C83E902F75A97E8FD374A /* menubar-1@2x.png in Resources */, + BF0C8C9CA44285E493918A74 /* menubar-2@2x.png in Resources */, BF0C829583ED47E458528F3A /* accessibility@2x.png in Resources */, BF0C8406805BDEC5B69E8803 /* screen-recording@2x.png in Resources */, BF0C853B271C4407E87FA183 /* InfoPlist.strings in Resources */, diff --git a/resources/icons/menubar/menubar-0.svg b/resources/icons/menubar/menubar-0.svg new file mode 100644 index 000000000..85c5165f7 --- /dev/null +++ b/resources/icons/menubar/menubar-0.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/icons/menubar/menubar-0@2x.png b/resources/icons/menubar/menubar-0@2x.png new file mode 100644 index 000000000..0281eb356 Binary files /dev/null and b/resources/icons/menubar/menubar-0@2x.png differ diff --git a/resources/icons/menubar/menubar-1.svg b/resources/icons/menubar/menubar-1.svg index 85c5165f7..da86be117 100644 --- a/resources/icons/menubar/menubar-1.svg +++ b/resources/icons/menubar/menubar-1.svg @@ -1,12 +1,11 @@ + + + - + - - - - - + diff --git a/resources/icons/menubar/menubar-1@2x.png b/resources/icons/menubar/menubar-1@2x.png index 0281eb356..09335ca9e 100644 Binary files a/resources/icons/menubar/menubar-1@2x.png and b/resources/icons/menubar/menubar-1@2x.png differ diff --git a/resources/icons/menubar/menubar-2.svg b/resources/icons/menubar/menubar-2.svg deleted file mode 100644 index da86be117..000000000 --- a/resources/icons/menubar/menubar-2.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/resources/icons/menubar/menubar-2@2x.png b/resources/icons/menubar/menubar-2@2x.png index 09335ca9e..7a76825b1 100644 Binary files a/resources/icons/menubar/menubar-2@2x.png and b/resources/icons/menubar/menubar-2@2x.png differ diff --git a/resources/icons/menubar/menubar-3@2x.png b/resources/icons/menubar/menubar-3@2x.png deleted file mode 100644 index 7a76825b1..000000000 Binary files a/resources/icons/menubar/menubar-3@2x.png and /dev/null differ diff --git a/src/logic/Preferences.swift b/src/logic/Preferences.swift index c16878e13..a91521646 100644 --- a/src/logic/Preferences.swift +++ b/src/logic/Preferences.swift @@ -80,6 +80,7 @@ class Preferences { "hideStatusIcons": "false", "startAtLogin": "true", "menubarIcon": MenubarIconPreference.outlined.indexAsString, + "menubarIconShown": "true", "language": LanguagePreference.systemDefault.indexAsString, "blacklist": defaultBlacklist(), "updatePolicy": UpdatePolicyPreference.autoCheck.indexAsString, @@ -156,6 +157,7 @@ class Preferences { static var windowOrder: [WindowOrderPreference] { ["windowOrder", "windowOrder2", "windowOrder3", "windowOrder4", "windowOrder5"].map { UserDefaults.standard.macroPref($0, WindowOrderPreference.allCases) } } static var shortcutStyle: [ShortcutStylePreference] { ["shortcutStyle", "shortcutStyle2", "shortcutStyle3", "shortcutStyle4", "shortcutStyle5"].map { UserDefaults.standard.macroPref($0, ShortcutStylePreference.allCases) } } static var menubarIcon: MenubarIconPreference { UserDefaults.standard.macroPref("menubarIcon", MenubarIconPreference.allCases) } + static var menubarIconShown: Bool { UserDefaults.standard.bool("menubarIconShown") } static var language: LanguagePreference { UserDefaults.standard.macroPref("language", LanguagePreference.allCases) } static func initialize() { @@ -199,38 +201,42 @@ class Preferences { static func migratePreferences() { let preferencesKey = "preferencesVersion" - if let diskVersion = UserDefaults.standard.string(forKey: preferencesKey) { - if diskVersion.compare(App.version, options: .numeric) == .orderedAscending { - updateToNewPreferences(diskVersion) + if let versionInPlist = UserDefaults.standard.string(forKey: preferencesKey) { + if versionInPlist.compare(App.version, options: .numeric) != .orderedDescending { + updateToNewPreferences(versionInPlist) } } UserDefaults.standard.set(App.version, forKey: preferencesKey) } - private static func updateToNewPreferences(_ currentVersion: String) { - if currentVersion.compare("6.72.0", options: .numeric) != .orderedDescending { - migratePreferencesIndexes() - if currentVersion.compare("6.42.0", options: .numeric) != .orderedDescending { - migrateBlacklists() - if currentVersion.compare("6.28.1", options: .numeric) != .orderedDescending { - migrateMinMaxWindowsWidthInRow() - if currentVersion.compare("6.27.1", options: .numeric) != .orderedDescending { - // "Start at login" new implem doesn't use Login Items; we remove the entry from previous versions - (Preferences.self as AvoidDeprecationWarnings.Type).migrateLoginItem() - if currentVersion.compare("6.23.0", options: .numeric) != .orderedDescending { - // "Show windows from:" got the "Active Space" option removed - migrateShowWindowsFrom() - if currentVersion.compare("6.18.1", options: .numeric) != .orderedDescending { - // nextWindowShortcut used to be able to have modifiers already present in holdShortcut; we remove these - migrateNextWindowShortcuts() - // dropdowns preferences used to store English text; now they store indexes - migrateDropdownsFromTextToIndexes() - // the "Hide menubar icon" checkbox was replaced with a dropdown of: icon1, icon2, hidden - migrateMenubarIconFromCheckboxToDropdown() - // "Show minimized/hidden/fullscreen windows" checkboxes were replaced with dropdowns - migrateShowWindowsCheckboxToDropdown() - // "Max size on screen" was split into max width and max height - migrateMaxSizeOnScreenToWidthAndHeight() + private static func updateToNewPreferences(_ versionInPlist: String) { + // x.compare(y) is .orderedDescending if x > y + if versionInPlist.compare("7.8.0", options: .numeric) != .orderedDescending { + migrateMenubarIconWithNewShownToggle() + if versionInPlist.compare("7.0.0", options: .numeric) != .orderedDescending { + migratePreferencesIndexes() + if versionInPlist.compare("6.43.0", options: .numeric) != .orderedDescending { + migrateBlacklists() + if versionInPlist.compare("6.28.1", options: .numeric) != .orderedDescending { + migrateMinMaxWindowsWidthInRow() + if versionInPlist.compare("6.27.1", options: .numeric) != .orderedDescending { + // "Start at login" new implem doesn't use Login Items; we remove the entry from previous versions + (Preferences.self as AvoidDeprecationWarnings.Type).migrateLoginItem() + if versionInPlist.compare("6.23.0", options: .numeric) != .orderedDescending { + // "Show windows from:" got the "Active Space" option removed + migrateShowWindowsFrom() + if versionInPlist.compare("6.18.1", options: .numeric) != .orderedDescending { + // nextWindowShortcut used to be able to have modifiers already present in holdShortcut; we remove these + migrateNextWindowShortcuts() + // dropdowns preferences used to store English text; now they store indexes + migrateDropdownsFromTextToIndexes() + // the "Hide menubar icon" checkbox was replaced with a dropdown of: icon1, icon2, hidden + migrateMenubarIconFromCheckboxToDropdown() + // "Show minimized/hidden/fullscreen windows" checkboxes were replaced with dropdowns + migrateShowWindowsCheckboxToDropdown() + // "Max size on screen" was split into max width and max height + migrateMaxSizeOnScreenToWidthAndHeight() + } } } } @@ -239,6 +245,17 @@ class Preferences { } } + // we added the new menubarIconShown toggle. It replaces menubarIcon having value "3" which would hide the icon + // there are now 2 preferences : menubarIconShown is a boolean, and menubarIcon has values 0, 1, 2 + private static func migrateMenubarIconWithNewShownToggle() { + if let old = UserDefaults.standard.string(forKey: "menubarIcon") { + if old == "3" { + UserDefaults.standard.set("0", forKey: "menubarIcon") + UserDefaults.standard.set("false", forKey: "menubarIconShown") + } + } + } + // we want to rely on preferences numbers to match the enum indexes. This migration realigns existing desyncs private static func migratePreferencesIndexes() { // migrate spacesToShow from 1 to 2. 1 was removed a while ago. 1=active => 2=>visible @@ -484,7 +501,6 @@ enum MenubarIconPreference: CaseIterable, MacroPreference { case outlined case filled case colored - case hidden var localizedString: LocalizedString { switch self { @@ -492,7 +508,6 @@ enum MenubarIconPreference: CaseIterable, MacroPreference { case .outlined: return " " case .filled: return " " case .colored: return " " - case .hidden: return " " } } } diff --git a/src/ui/Menubar.swift b/src/ui/Menubar.swift index 7eec8f861..85487d565 100644 --- a/src/ui/Menubar.swift +++ b/src/ui/Menubar.swift @@ -50,7 +50,6 @@ class Menubar { statusItem.target = self statusItem.button!.action = #selector(statusItemOnClick) statusItem.button!.sendAction(on: [.leftMouseDown, .rightMouseDown]) - menubarIconCallback(nil) } // NSMenuItem.isHidden isn't reliable with custom views. We add/remove to hide/show these items @@ -75,30 +74,24 @@ class Menubar { } static func menubarIconCallback(_: NSControl?) { - if Preferences.menubarIcon == .hidden { - statusItem.isVisible = false - } else { + if Preferences.menubarIconShown { loadPreferredIcon() + } else { + statusItem.isVisible = false + } + if let menubarIconDropdown = GeneralTab.menubarIconDropdown { + menubarIconDropdown.isEnabled = Preferences.menubarIconShown } } static private func loadPreferredIcon() { - let i = imageIndexFromPreference() - let image = NSImage(named: "menubar-" + i)! - image.isTemplate = i == "3" ? false : true + let i = Preferences.menubarIcon.indexAsString + let image = NSImage(named: "menubar-\(i)")! + image.isTemplate = i < 2 statusItem.button!.image = image statusItem.isVisible = true statusItem.button!.imageScaling = .scaleProportionallyUpOrDown } - - static private func imageIndexFromPreference() -> String { - switch Preferences.menubarIcon { - case .outlined: return "1" - case .filled: return "2" - case .colored: return "3" - default: return "4" - } - } } class PermissionCallout: StackView { diff --git a/src/ui/preferences-window/LabelAndControl.swift b/src/ui/preferences-window/LabelAndControl.swift index 44823c32c..2af018ec4 100644 --- a/src/ui/preferences-window/LabelAndControl.swift +++ b/src/ui/preferences-window/LabelAndControl.swift @@ -115,7 +115,7 @@ class LabelAndControl: NSObject { return views } - static func makeSwitch(_ rawName: String, extraAction: ActionClosure? = nil) -> NSControl { + static func makeSwitch(_ rawName: String, extraAction: ActionClosure? = nil) -> Switch { let button = Switch(UserDefaults.standard.bool(rawName)) _ = setupControl(button, rawName, extraAction: extraAction) return button diff --git a/src/ui/preferences-window/tabs/GeneralTab.swift b/src/ui/preferences-window/tabs/GeneralTab.swift index 350a82066..b02115a2e 100644 --- a/src/ui/preferences-window/tabs/GeneralTab.swift +++ b/src/ui/preferences-window/tabs/GeneralTab.swift @@ -18,31 +18,37 @@ class GeneralTab { // efficient but more precise behavior and not be coalesced with other timers. "LegacyTimers": true, ] + static var menubarIconDropdown: NSPopUpButton? private static var menubarIsVisibleObserver: NSKeyValueObservation? static func initTab() -> NSView { let startAtLogin = TableGroupView.Row(leftTitle: NSLocalizedString("Start at login", comment: ""), rightViews: [LabelAndControl.makeSwitch("startAtLogin", extraAction: startAtLoginCallback)]) + menubarIconDropdown = LabelAndControl.makeDropdown("menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback) + let menuIconShownToggle = LabelAndControl.makeSwitch("menubarIconShown", extraAction: Menubar.menubarIconCallback) let menubarIcon = TableGroupView.Row(leftTitle: NSLocalizedString("Menubar icon", comment: ""), - rightViews: [LabelAndControl.makeDropdown("menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback)]) + rightViews: [ + menubarIconDropdown!, + menuIconShownToggle, + ]) let language = TableGroupView.Row(leftTitle: NSLocalizedString("Language", comment: ""), rightViews: [LabelAndControl.makeDropdown("language", LanguagePreference.allCases, extraAction: setLanguageCallback)]) let resetPreferences = NSButton(title: NSLocalizedString("Reset preferences and restart…", comment: ""), target: self, action: #selector(GeneralTab.resetPreferences)) if #available(macOS 11.0, *) { resetPreferences.hasDestructiveAction = true } - let menubarIconDropdown = menubarIcon.rightViews[0] as! NSPopUpButton - for i in 0...2 { - let image = NSImage.initCopy("menubar-" + String(i + 1)) + for i in 0..