File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Coder-Desktop/Coder-Desktop Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -20,20 +20,23 @@ struct DesktopApp: App {
2020 Window ( " Sign In " , id: Windows . login. rawValue) {
2121 LoginForm ( )
2222 . environmentObject ( appDelegate. state)
23+ . showDockIconWhenOpen ( )
2324 } . handlesExternalEvents ( matching: Set ( ) ) // Don't handle deep links
2425 . windowResizability ( . contentSize)
2526 SwiftUI . Settings {
2627 SettingsView < CoderVPNService > ( )
2728 . environmentObject ( appDelegate. vpn)
2829 . environmentObject ( appDelegate. state)
2930 . environmentObject ( appDelegate. autoUpdater)
31+ . showDockIconWhenOpen ( )
3032 }
3133 . windowResizability ( . contentSize)
3234 Window ( " Coder File Sync " , id: Windows . fileSync. rawValue) {
3335 FileSyncConfig < CoderVPNService , MutagenDaemon > ( )
3436 . environmentObject ( appDelegate. state)
3537 . environmentObject ( appDelegate. fileSyncDaemon)
3638 . environmentObject ( appDelegate. vpn)
39+ . showDockIconWhenOpen ( )
3740 } . handlesExternalEvents ( matching: Set ( ) ) // Don't handle deep links
3841 }
3942}
Original file line number Diff line number Diff line change @@ -44,3 +44,26 @@ public extension View {
4444 }
4545 }
4646}
47+
48+ @MainActor
49+ private struct ActivationPolicyModifier : ViewModifier {
50+ func body( content: Content ) -> some View {
51+ content
52+ // This lets us show and hide the app from the dock and cmd+tab
53+ // when a window is open.
54+ . onAppear {
55+ NSApp . setActivationPolicy ( . regular)
56+ }
57+ . onDisappear {
58+ if NSApp . windows. filter { $0. level != . statusBar && $0. isVisible } . count <= 1 {
59+ NSApp . setActivationPolicy ( . accessory)
60+ }
61+ }
62+ }
63+ }
64+
65+ public extension View {
66+ func showDockIconWhenOpen( ) -> some View {
67+ modifier ( ActivationPolicyModifier ( ) )
68+ }
69+ }
You can’t perform that action at this time.
0 commit comments