Skip to content

feat: show an alert when the menu bar icon is hidden #153

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

Merged
merged 1 commit into from
May 8, 2025
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
23 changes: 23 additions & 0 deletions Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions Coder-Desktop/Coder-Desktop/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -209,6 +216,8 @@ class AppState: ObservableObject {
static let literalHeaders = "LiteralHeaders"
static let stopVPNOnQuit = "StopVPNOnQuit"
static let startVPNOnLaunch = "StartVPNOnLaunch"

static let skipHiddenIconAlert = "SkipHiddenIconAlert"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Coder-Desktop/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading