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 {
20
20
Window ( " Sign In " , id: Windows . login. rawValue) {
21
21
LoginForm ( )
22
22
. environmentObject ( appDelegate. state)
23
+ . showDockIconWhenOpen ( )
23
24
} . handlesExternalEvents ( matching: Set ( ) ) // Don't handle deep links
24
25
. windowResizability ( . contentSize)
25
26
SwiftUI . Settings {
26
27
SettingsView < CoderVPNService > ( )
27
28
. environmentObject ( appDelegate. vpn)
28
29
. environmentObject ( appDelegate. state)
29
30
. environmentObject ( appDelegate. autoUpdater)
31
+ . showDockIconWhenOpen ( )
30
32
}
31
33
. windowResizability ( . contentSize)
32
34
Window ( " Coder File Sync " , id: Windows . fileSync. rawValue) {
33
35
FileSyncConfig < CoderVPNService , MutagenDaemon > ( )
34
36
. environmentObject ( appDelegate. state)
35
37
. environmentObject ( appDelegate. fileSyncDaemon)
36
38
. environmentObject ( appDelegate. vpn)
39
+ . showDockIconWhenOpen ( )
37
40
} . handlesExternalEvents ( matching: Set ( ) ) // Don't handle deep links
38
41
}
39
42
}
Original file line number Diff line number Diff line change @@ -44,3 +44,26 @@ public extension View {
44
44
}
45
45
}
46
46
}
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