Skip to content

feat: dynamically show app in dock & cmd+tab #224

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
Aug 13, 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
3 changes: 3 additions & 0 deletions Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@ struct DesktopApp: App {
Window("Sign In", id: Windows.login.rawValue) {
LoginForm()
.environmentObject(appDelegate.state)
.showDockIconWhenOpen()
}.handlesExternalEvents(matching: Set()) // Don't handle deep links
.windowResizability(.contentSize)
SwiftUI.Settings {
SettingsView<CoderVPNService>()
.environmentObject(appDelegate.vpn)
.environmentObject(appDelegate.state)
.environmentObject(appDelegate.autoUpdater)
.showDockIconWhenOpen()
}
.windowResizability(.contentSize)
Window("Coder File Sync", id: Windows.fileSync.rawValue) {
FileSyncConfig<CoderVPNService, MutagenDaemon>()
.environmentObject(appDelegate.state)
.environmentObject(appDelegate.fileSyncDaemon)
.environmentObject(appDelegate.vpn)
.showDockIconWhenOpen()
}.handlesExternalEvents(matching: Set()) // Don't handle deep links
}
}
Expand Down
23 changes: 23 additions & 0 deletions Coder-Desktop/Coder-Desktop/Views/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@
}
}
}

@MainActor
private struct ActivationPolicyModifier: ViewModifier {
func body(content: Content) -> some View {
content
// This lets us show and hide the app from the dock and cmd+tab
// when a window is open.
.onAppear {
NSApp.setActivationPolicy(.regular)
}
.onDisappear {
if NSApp.windows.filter { $0.level != .statusBar && $0.isVisible }.count <= 1 {

Check warning on line 58 in Coder-Desktop/Coder-Desktop/Views/Util.swift

View workflow job for this annotation

GitHub Actions / test

trailing closure in this context is confusable with the body of the statement; pass as a parenthesized argument to silence this warning
NSApp.setActivationPolicy(.accessory)
}
}
}
}

public extension View {
func showDockIconWhenOpen() -> some View {
modifier(ActivationPolicyModifier())
}
}
Loading