@@ -5,6 +5,7 @@ struct Agents<VPN: VPNService>: View {
5
5
@EnvironmentObject var state : AppState
6
6
@State private var viewAll = false
7
7
@State private var expandedItem : VPNMenuItem . ID ?
8
+ @State private var hasToggledExpansion : Bool = false
8
9
private let defaultVisibleRows = 5
9
10
10
11
let inspection = Inspection < Self > ( )
@@ -16,8 +17,25 @@ struct Agents<VPN: VPNService>: View {
16
17
let items = vpn. menuState. sorted
17
18
let visibleItems = viewAll ? items [ ... ] : items. prefix ( defaultVisibleRows)
18
19
ForEach ( visibleItems, id: \. id) { agent in
19
- MenuItemView ( item: agent, baseAccessURL: state. baseAccessURL!, expandedItem: $expandedItem)
20
- . padding ( . horizontal, Theme . Size. trayMargin)
20
+ MenuItemView (
21
+ item: agent,
22
+ baseAccessURL: state. baseAccessURL!,
23
+ expandedItem: $expandedItem,
24
+ userInteracted: $hasToggledExpansion
25
+ )
26
+ . padding ( . horizontal, Theme . Size. trayMargin)
27
+ } . onChange ( of: visibleItems) {
28
+ // If no workspaces are online, we should expand the first one to come online
29
+ if visibleItems. filter ( { $0. status != . off } ) . isEmpty {
30
+ hasToggledExpansion = false
31
+ return
32
+ }
33
+ // If an active workspace is expanded, or has been
34
+ if hasToggledExpansion {
35
+ return
36
+ }
37
+ expandedItem = visibleItems. first? . id
38
+ hasToggledExpansion = true
21
39
}
22
40
if items. count == 0 {
23
41
Text ( " No workspaces! " )
0 commit comments