From ec00ef2802952774a8dadbd6a13836889f2e88bc Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Thu, 8 May 2025 13:06:07 +1000 Subject: [PATCH] feat: show an alert when the menu bar icon is hidden --- .../Coder-Desktop/Coder_DesktopApp.swift | 23 +++++++++++++++++++ Coder-Desktop/Coder-Desktop/State.swift | 9 ++++++++ Coder-Desktop/project.yml | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift b/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift index 4ec412f..d9cd649 100644 --- a/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift +++ b/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift @@ -126,6 +126,29 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool { false } + + func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows _: Bool) -> Bool { + if !state.skipHiddenIconAlert, let menuBar, !menuBar.menuBarExtra.isVisible { + displayIconHiddenAlert() + } + return true + } + + private func displayIconHiddenAlert() { + let alert = NSAlert() + alert.alertStyle = .informational + alert.messageText = "Coder Desktop is hidden!" + alert.informativeText = """ + Coder Desktop is running, but there's no space in the menu bar for it's icon. + You can rearrange icons by holding command. + """ + alert.addButton(withTitle: "OK") + alert.addButton(withTitle: "Don't show again") + let resp = alert.runModal() + if resp == .alertSecondButtonReturn { + state.skipHiddenIconAlert = true + } + } } extension AppDelegate { diff --git a/Coder-Desktop/Coder-Desktop/State.swift b/Coder-Desktop/Coder-Desktop/State.swift index 2247c46..e9a0248 100644 --- a/Coder-Desktop/Coder-Desktop/State.swift +++ b/Coder-Desktop/Coder-Desktop/State.swift @@ -69,6 +69,13 @@ class AppState: ObservableObject { } } + @Published var skipHiddenIconAlert: Bool = UserDefaults.standard.bool(forKey: Keys.skipHiddenIconAlert) { + didSet { + guard persistent else { return } + UserDefaults.standard.set(skipHiddenIconAlert, forKey: Keys.skipHiddenIconAlert) + } + } + func tunnelProviderProtocol() -> NETunnelProviderProtocol? { if !hasSession { return nil } let proto = NETunnelProviderProtocol() @@ -209,6 +216,8 @@ class AppState: ObservableObject { static let literalHeaders = "LiteralHeaders" static let stopVPNOnQuit = "StopVPNOnQuit" static let startVPNOnLaunch = "StartVPNOnLaunch" + + static let skipHiddenIconAlert = "SkipHiddenIconAlert" } } diff --git a/Coder-Desktop/project.yml b/Coder-Desktop/project.yml index f557304..701d648 100644 --- a/Coder-Desktop/project.yml +++ b/Coder-Desktop/project.yml @@ -97,7 +97,7 @@ packages: # - Set onAppear/disappear handlers. # The upstream repo has a purposefully limited API url: https://github.com/coder/fluid-menu-bar-extra - revision: 96a861a + revision: 8e1d8b8 KeychainAccess: url: https://github.com/kishikawakatsumi/KeychainAccess branch: e0c7eebc5a4465a3c4680764f26b7a61f567cdaf