Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 565665f

Browse files
feat: show an alert when the menu bar icon is hidden (#153)
Relates to #148. If the menu bar icon is hidden (such as when behind the notch, or otherwise), reopening the app will display an alert that the icon is hidden. There's also a button to not show the alert again. I've also tested that this, and the 'Do not show again' button, work in a fresh VM. This is the same as what Tailscale does: https://github.com/user-attachments/assets/dae6d9ed-eab2-404f-8522-314042bdd1d8
1 parent f039526 commit 565665f

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift

+23
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
126126
func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
127127
false
128128
}
129+
130+
func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows _: Bool) -> Bool {
131+
if !state.skipHiddenIconAlert, let menuBar, !menuBar.menuBarExtra.isVisible {
132+
displayIconHiddenAlert()
133+
}
134+
return true
135+
}
136+
137+
private func displayIconHiddenAlert() {
138+
let alert = NSAlert()
139+
alert.alertStyle = .informational
140+
alert.messageText = "Coder Desktop is hidden!"
141+
alert.informativeText = """
142+
Coder Desktop is running, but there's no space in the menu bar for it's icon.
143+
You can rearrange icons by holding command.
144+
"""
145+
alert.addButton(withTitle: "OK")
146+
alert.addButton(withTitle: "Don't show again")
147+
let resp = alert.runModal()
148+
if resp == .alertSecondButtonReturn {
149+
state.skipHiddenIconAlert = true
150+
}
151+
}
129152
}
130153

131154
extension AppDelegate {

Coder-Desktop/Coder-Desktop/State.swift

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class AppState: ObservableObject {
6969
}
7070
}
7171

72+
@Published var skipHiddenIconAlert: Bool = UserDefaults.standard.bool(forKey: Keys.skipHiddenIconAlert) {
73+
didSet {
74+
guard persistent else { return }
75+
UserDefaults.standard.set(skipHiddenIconAlert, forKey: Keys.skipHiddenIconAlert)
76+
}
77+
}
78+
7279
func tunnelProviderProtocol() -> NETunnelProviderProtocol? {
7380
if !hasSession { return nil }
7481
let proto = NETunnelProviderProtocol()
@@ -209,6 +216,8 @@ class AppState: ObservableObject {
209216
static let literalHeaders = "LiteralHeaders"
210217
static let stopVPNOnQuit = "StopVPNOnQuit"
211218
static let startVPNOnLaunch = "StartVPNOnLaunch"
219+
220+
static let skipHiddenIconAlert = "SkipHiddenIconAlert"
212221
}
213222
}
214223

Coder-Desktop/project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ packages:
9797
# - Set onAppear/disappear handlers.
9898
# The upstream repo has a purposefully limited API
9999
url: https://github.com/coder/fluid-menu-bar-extra
100-
revision: 96a861a
100+
revision: 8e1d8b8
101101
KeychainAccess:
102102
url: https://github.com/kishikawakatsumi/KeychainAccess
103103
branch: e0c7eebc5a4465a3c4680764f26b7a61f567cdaf

0 commit comments

Comments
 (0)