SPB Git

Repository Public License

NavigatoriOSApp.swift 1.7 KB 51 lines swift

1import NavigatorCore2import NavigatorFeatures3import NavigatorUI4import SwiftUI5import UIKit67@main8struct NavigatoriOSApp: App {9    @Environment(\.scenePhase) private var scenePhase1011    init() {12        let environment = AppEnvironment.shared13        // Features plug into the shell before the first scene is built.14        NavigatorFeatures.registerAll(in: environment.registry)15        environment.configureStore = { store in16            environment.retained.append(PhonePlatformSupport(store: store))17        }18        environment.start()19    }2021    var body: some Scene {22        WindowGroup(for: WindowID.self) { $windowID in23            NavigatorSceneView(windowID: $windowID)24                .onOpenURL { AppEnvironment.shared.open(urls: [$0]) }25        }26        .commands { BrowserCommands() }27        .onChange(of: scenePhase) { _, phase in28            switch phase {29            case .background: persistSession()30            case .active: Task { await AppEnvironment.shared.resume() }31            default: break32            }33        }34    }3536    /// iOS may end the process at any time once it is in the background: the session is written and marked clean37    /// under a background task assertion.38    private func persistSession() {39        let application = UIApplication.shared40        var identifier = UIBackgroundTaskIdentifier.invalid41        identifier = application.beginBackgroundTask(withName: "ai.spboucher.orix.navigator.session") {42            application.endBackgroundTask(identifier)43            identifier = .invalid44        }45        Task {46            await AppEnvironment.shared.suspend()47            if identifier != .invalid { application.endBackgroundTask(identifier) }48        }49    }50}51
Files main
Menu

Theme