commit b13a08df19a443ae0c6489e0777c4e490506a0ea
parent 8a8a54a3391c8db354f146975872048f098ec22a
Author: Marc Stibane <marc@taler.net>
Date: Thu, 5 Jun 2025 14:00:15 +0200
hintApplicationResumed
Diffstat:
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/TalerWallet1/Controllers/TalerWallet1App.swift b/TalerWallet1/Controllers/TalerWallet1App.swift
@@ -19,7 +19,7 @@ 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 isActive = true
+ @State private var backgrounded: Date?
@State private var soundPlayed = false
private let walletCore = WalletCore.shared
@@ -34,6 +34,11 @@ 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)
@@ -51,11 +56,18 @@ struct TalerWallet1App: App {
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification, object: nil)) { _ in
logger.log("❗️App Will Resign")
- isActive = false
+ backgrounded = Date.now
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification, object: nil)) { _ in
logger.log("❗️App Will Enter Foreground")
- isActive = true
+ 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()
+ }
+ }
+ backgrounded = nil
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification, object: nil)) { _ in
logger.log("❗️App Did Become Active")
diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift
@@ -158,6 +158,14 @@ class WalletModel: ObservableObject {
}
// MARK: -
/// A request to tell wallet-core about the network.
+fileprivate struct ApplicationResumedRequest: WalletBackendFormattedRequest {
+ struct Response: Decodable {}
+ func operation() -> String { "hintApplicationResumed" }
+ func args() -> Args { Args() }
+
+ struct Args: Encodable {} // no arguments needed
+}
+
fileprivate struct NetworkAvailabilityRequest: WalletBackendFormattedRequest {
struct Response: Decodable {}
func operation() -> String { "hintNetworkAvailability" }
@@ -176,6 +184,11 @@ extension WalletModel {
let request = NetworkAvailabilityRequest(isNetworkAvailable: isNetworkAvailable)
_ = try? await sendRequest(request)
}
+ func hintApplicationResumedT() async {
+ // T for any Thread
+ let request = ApplicationResumedRequest()
+ _ = try? await sendRequest(request)
+ }
}
// MARK: -
/// A request to get a wallet transaction by ID.