@@ -5,6 +5,7 @@ struct Agents<VPN: VPNService>: View {
55 @EnvironmentObject var state : AppState
66 @State private var viewAll = false
77 @State private var expandedItem : VPNMenuItem . ID ?
8+ @State private var hasToggledExpansion : Bool = false
89 private let defaultVisibleRows = 5
910
1011 let inspection = Inspection < Self > ( )
@@ -16,8 +17,24 @@ struct Agents<VPN: VPNService>: View {
1617 let items = vpn. menuState. sorted
1718 let visibleItems = viewAll ? items [ ... ] : items. prefix ( defaultVisibleRows)
1819 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 hasToggledExpansion {
34+ return
35+ }
36+ expandedItem = visibleItems. first? . id
37+ hasToggledExpansion = true
2138 }
2239 if items. count == 0 {
2340 Text ( " No workspaces! " )
0 commit comments