@@ -167,7 +167,9 @@ struct RootView: View {
167
167
@Environment ( \. openWindow) var openWindow
168
168
@Environment ( \. controlActiveState) var controlActiveState
169
169
@StateObject private var navigation = NavigationViewModel ( )
170
+ @State private var currentNavItem : NavigationItem ?
170
171
@StateObject private var windowTracker = WindowTracker ( )
172
+ @State private var paymentButtonLabel : PayWithApplePayButtonLabel ?
171
173
172
174
private let primaryItems : [ NavigationItem ] = [ . bookmarks]
173
175
private let libraryItems : [ NavigationItem ] = [ . opened, . categories, . downloads, . new]
@@ -179,7 +181,7 @@ struct RootView: View {
179
181
180
182
var body : some View {
181
183
NavigationSplitView {
182
- List ( selection: $navigation . currentItem ) {
184
+ List ( selection: $currentNavItem ) {
183
185
ForEach (
184
186
[ NavigationItem . tab ( objectID: navigation. currentTabId) ] + primaryItems,
185
187
id: \. self
@@ -196,7 +198,7 @@ struct RootView: View {
196
198
}
197
199
. frame ( minWidth: 160 )
198
200
. safeAreaInset ( edge: . bottom) {
199
- if Payment . paymentButtonType ( ) != nil && Brand . hideDonation != true {
201
+ if paymentButtonLabel != nil && Brand . hideDonation != true {
200
202
SupportKiwixButton {
201
203
openWindow ( id: " donation " )
202
204
}
@@ -229,6 +231,9 @@ struct RootView: View {
229
231
. modifier ( OpenFileHandler ( ) )
230
232
. modifier ( SaveContentHandler ( ) )
231
233
. environmentObject ( navigation)
234
+ . onChange ( of: currentNavItem) { newValue in
235
+ navigation. currentItem = newValue
236
+ }
232
237
. onOpenURL { url in
233
238
if url. isFileURL {
234
239
// from opening an external file
@@ -267,7 +272,7 @@ struct RootView: View {
267
272
}
268
273
guard controlActiveState == . key else { return }
269
274
let tabID = navigation. currentTabId
270
- navigation . currentItem = . tab( objectID: tabID)
275
+ currentNavItem = . tab( objectID: tabID)
271
276
BrowserViewModel . getCached ( tabID: tabID) . load ( url: url)
272
277
}
273
278
. onReceive ( tabCloses) { publisher in
@@ -303,15 +308,20 @@ struct RootView: View {
303
308
switch AppType . current {
304
309
case . kiwix:
305
310
await LibraryOperations . reopen ( )
306
- navigation . currentItem = . tab( objectID: navigation. currentTabId)
311
+ currentNavItem = . tab( objectID: navigation. currentTabId)
307
312
LibraryOperations . scanDirectory ( URL . documentDirectory)
308
313
LibraryOperations . applyFileBackupSetting ( )
309
314
DownloadService . shared. restartHeartbeatIfNeeded ( )
310
315
case let . custom( zimFileURL) :
311
316
await LibraryOperations . open ( url: zimFileURL)
312
317
ZimMigration . forCustomApps ( )
313
- navigation. currentItem = . tab( objectID: navigation. currentTabId)
318
+ currentNavItem = . tab( objectID: navigation. currentTabId)
319
+ }
320
+ // MARK: - payment button init
321
+ if Brand . hideDonation == false {
322
+ paymentButtonLabel = await Payment . paymentButtonTypeAsync ( )
314
323
}
324
+
315
325
// MARK: - migrations
316
326
if !ProcessInfo. processInfo. arguments. contains ( " testing " ) {
317
327
_ = MigrationService ( ) . migrateAll ( )
0 commit comments