taler-ios

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

commit 7ded59c6deb9d4646a29c2d00c57751f34fd5be4
parent 3745daec876d0e23aca0b827481fb9ad6d76c287
Author: Marc Stibane <marc@taler.net>
Date:   Tue, 27 Jun 2023 14:46:01 +0200

playSound

Diffstat:
MTalerWallet1/Controllers/TalerWallet1App.swift | 3++-
MTalerWallet1/Views/Main/MainView.swift | 14++++++++++++++
MTalerWallet1/Views/Payment/PaymentURIView.swift | 1+
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift | 9+++++----
4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/TalerWallet1/Controllers/TalerWallet1App.swift b/TalerWallet1/Controllers/TalerWallet1App.swift @@ -19,6 +19,7 @@ struct TalerWallet1App: App { @Environment(\.scenePhase) private var phase @StateObject private var viewState = ViewState.shared // popToRootView() @State private var isActive = true + @State private var soundPlayed = false private let walletCore = WalletCore.shared // our main controller @@ -35,7 +36,7 @@ struct TalerWallet1App: App { var body: some Scene { WindowGroup { - MainView() + MainView(soundPlayed: $soundPlayed) .environmentObject(debugViewC) // change viewID / sheetID .environmentObject(viewState) // popToRoot .environmentObject(controller) diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -19,7 +19,17 @@ struct MainView: View { @EnvironmentObject private var controller: Controller @State private var sheetPresented = false @State private var urlToOpen: URL? = nil + @Binding var soundPlayed: Bool + func playSound() -> Void { + if !soundPlayed { + let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/" + + "PaymentReceived.caf") + // + "payment_success.caf") + // + "payment_failure.caf") + GNU_Taler.playSound(fileURL: url) + } + } func sheetDismissed() -> Void { symLog.log("sheet dismiss") } @@ -33,6 +43,10 @@ struct MainView: View { Content(symLog: symLog) // any change to rootViewId triggers popToRootView behaviour .id(viewState.rootViewId) + .onAppear() { + playSound() + soundPlayed = true + } } else if controller.backendState == .error { ErrorView(errortext: nil) // TODO: show Error View } else { diff --git a/TalerWallet1/Views/Payment/PaymentURIView.swift b/TalerWallet1/Views/Payment/PaymentURIView.swift @@ -36,6 +36,7 @@ struct PaymentURIView: View { } } } catch { // TODO: error + playSound(success: false) symLog.log(error.localizedDescription) } dismissTop() diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift @@ -16,9 +16,10 @@ struct P2pAcceptDone: View { @State private var finished: Bool = false - func playSound(success: Bool) { + func playSound(success: Bool, incoming: Bool) { let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/" - + (success ? "PaymentReceived.caf" + + (success ? (incoming ? "PaymentReceived.caf" + : "payment_success.caf") : "payment_failure.caf")) GNU_Taler.playSound(fileURL: url) } @@ -52,10 +53,10 @@ struct P2pAcceptDone: View { _ = try await model.confirmPeerPullDebitM(transactionId) } finished = true - playSound(success: true) + playSound(success: true, incoming: incoming) } catch { // TODO: error symLog.log(error.localizedDescription) - playSound(success: false) + playSound(success: false, incoming: incoming) } } }