taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 7be94b1c1fa26f54d197b4a5aad3e59baa232156
parent e92cccb4a2b5c6be7a5f1148a8f15d1375ee95b4
Author: Marc Stibane <marc@taler.net>
Date:   Sun,  7 Sep 2025 18:31:44 +0200

dismiss QR scanner in background

Diffstat:
MTalerWallet1/Controllers/TalerWallet1App.swift | 27---------------------------
MTalerWallet1/Views/Main/MainView.swift | 28++++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/TalerWallet1/Controllers/TalerWallet1App.swift b/TalerWallet1/Controllers/TalerWallet1App.swift @@ -19,7 +19,6 @@ struct TalerWallet1App: App { @Environment(\.scenePhase) private var phase @StateObject private var viewState = ViewState.shared // popToRootView() @StateObject private var viewState2 = ViewState2.shared // popToRootView() - @State private var backgrounded: Date? @State private var soundPlayed = false private let walletCore = WalletCore.shared @@ -35,11 +34,6 @@ struct TalerWallet1App: App { try? BGTaskScheduler.shared.submit(request) } - func hintApplicationResumed() { - Task.detached { - await model.hintApplicationResumedT() - } - } var body: some Scene { WindowGroup { MainView(logger: logger, stack: CallStack("App"), soundPlayed: $soundPlayed) @@ -56,27 +50,6 @@ struct TalerWallet1App: App { .task { try! await controller.initWalletCore(model, setTesting: false) // will (and should) crash on failure } - .onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification, object: nil)) { _ in - logger.log("❗️App Will Resign") - backgrounded = Date.now - } - .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification, object: nil)) { _ in - logger.log("❗️App Will Enter Foreground") - if let backgrounded { - let interval = Date.now - backgrounded - if interval.seconds > 300 { // 5 minutes - logger.log("More than 5 minutes in background - tell wallet-core") - hintApplicationResumed() - } - if interval.seconds > 60 { - biometricService.isAuthenticated = false - } - } - backgrounded = nil - } - .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification, object: nil)) { _ in - logger.log("❗️App Did Become Active") - } } .onChange(of: phase) { newPhase in switch newPhase { diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -44,6 +44,7 @@ struct MainView: View { @State private var innerHeight: CGFloat = .zero @State private var userAction = 0 @State private var networkUnavailable = false + @State private var backgrounded: Date? func sheetDismissed() -> Void { logger.info("sheet dismiss") @@ -64,6 +65,11 @@ struct MainView: View { userAction += 1 } + func hintApplicationResumed() { + Task.detached { + await model.hintApplicationResumedT() + } + } var body: some View { #if PRINT_CHANGES let _ = Self._printChanges() @@ -259,9 +265,31 @@ struct MainView: View { } else { withAnimation(.easeOut(duration: 1.0)) { networkUnavailable = true + } } } + + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification, object: nil)) { _ in + logger.log("❗️App Will Resign") + backgrounded = Date.now + showScanner = false + } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification, object: nil)) { _ in + logger.log("❗️App Will Enter Foreground") + if let backgrounded { + let interval = Date.now - backgrounded + if interval.seconds > 60 { + biometricService.isAuthenticated = false + if interval.seconds > 300 { // 5 minutes + logger.log("More than 5 minutes in background - tell wallet-core") + hintApplicationResumed() + } } } + backgrounded = nil } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification, object: nil)) { _ in + logger.log("❗️App Did Become Active") + } + } // body } // MARK: - TabBar