@@ -39,6 +39,8 @@ private struct NavigationState: Codable {
39
39
@MainActor
40
40
class NavigationModel : ObservableObject {
41
41
static let shared = NavigationModel ( )
42
+
43
+ private let log = Log . scoped ( " Navigation " , enableTracing: true )
42
44
43
45
@Published var homePath : [ NavigationRoute ] = [ ]
44
46
@Published var homeSelection : NavigationRoute = . homeRoot
@@ -51,7 +53,13 @@ class NavigationModel: ObservableObject {
51
53
@Published private var spacePathDict : [ Int64 : [ NavigationRoute ] ] = [ : ]
52
54
@Published private var spaceSelectionDict : [ Int64 : NavigationRoute ] = [ : ]
53
55
54
- public var windowManager : MainWindowViewModel ?
56
+ public var windowManager : MainWindowViewModel ? {
57
+ didSet {
58
+ log. trace ( " windowManager set " )
59
+ // upon window creation
60
+ prepareForCurrentRoute ( )
61
+ }
62
+ }
55
63
56
64
var spacePath : Binding < [ NavigationRoute ] > {
57
65
Binding (
@@ -96,8 +104,8 @@ class NavigationModel: ObservableObject {
96
104
private var cancellables = Set < AnyCancellable > ( )
97
105
98
106
init ( ) {
99
- loadState ( )
100
107
setupSubscriptions ( )
108
+ loadState ( )
101
109
setupStatePersistence ( )
102
110
}
103
111
@@ -117,6 +125,14 @@ class NavigationModel: ObservableObject {
117
125
} . store ( in: & cancellables)
118
126
}
119
127
128
+ private func prepareForCurrentRoute( ) {
129
+ if let activeSpaceId {
130
+ windowManager? . setUpForInnerRoute ( spaceSelectionDict [ activeSpaceId] ?? . spaceRoot)
131
+ } else {
132
+ windowManager? . setUpForInnerRoute ( homePath. last ?? homeSelection)
133
+ }
134
+ }
135
+
120
136
// Used from sidebars
121
137
func select( _ route: NavigationRoute ) {
122
138
if let activeSpaceId {
0 commit comments