taler-ios

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

commit e77028d251183015f2881da2ca78da5e168d84d6
parent 74dd08d6c17b9fa23945e7d88be031ebe9deeff9
Author: Marc Stibane <marc@taler.net>
Date:   Wed, 28 Jun 2023 17:05:15 +0200

playSound

Diffstat:
MTalerWallet1/Helper/playSound.swift | 6+++++-
MTalerWallet1/Views/Main/MainView.swift | 11+----------
MTalerWallet1/Views/Payment/PaymentURIView.swift | 13+++----------
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift | 12++----------
MTalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift | 2++
5 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/TalerWallet1/Helper/playSound.swift b/TalerWallet1/Helper/playSound.swift @@ -5,7 +5,11 @@ import Foundation import AVFoundation -func playSound(fileURL: URL) { +func playSound(_ number: Int) { + let sound = (number == 0) ? "payment_failure" : + (number == 1) ? "payment_success" : "PaymentReceived" + let fileURL = URL(fileURLWithPath: "/System/Library/Audio/UISounds/" + + sound + ".caf") var soundID: SystemSoundID = 0 AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID) AudioServicesPlaySystemSound(soundID); diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -21,15 +21,6 @@ struct MainView: View { @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") } @@ -44,7 +35,7 @@ struct MainView: View { // any change to rootViewId triggers popToRootView behaviour .id(viewState.rootViewId) .onAppear() { - playSound() + GNU_Taler.playSound(2) soundPlayed = true } } else if controller.backendState == .error { diff --git a/TalerWallet1/Views/Payment/PaymentURIView.swift b/TalerWallet1/Views/Payment/PaymentURIView.swift @@ -17,27 +17,20 @@ struct PaymentURIView: View { @EnvironmentObject private var model: WalletModel - - func playSound(success: Bool) { - let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/payment_" - + (success ? "success.caf" : "failure.caf")) - GNU_Taler.playSound(fileURL: url) - } - func acceptAction(detailsForUri: PaymentDetailsForUri) { Task { do { let confirmPayResult = try await model.confirmPayM(detailsForUri.proposalId) symLog.log(confirmPayResult as Any) if confirmPayResult.type == "done" { - playSound(success: true) + GNU_Taler.playSound(1) // TODO: Show Hints that Payment was successfull } else { - playSound(success: false) + GNU_Taler.playSound(0) // TODO: show error } } catch { - playSound(success: false) + GNU_Taler.playSound(0) // TODO: error symLog.log(error.localizedDescription) } diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift @@ -16,14 +16,6 @@ struct P2pAcceptDone: View { @State private var finished: Bool = false - func playSound(success: Bool, incoming: Bool) { - let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/" - + (success ? (incoming ? "PaymentReceived.caf" - : "payment_success.caf") - : "payment_failure.caf")) - GNU_Taler.playSound(fileURL: url) - } - func reloadOneAction(_ transactionId: String) async throws -> Transaction { return try await model.getTransactionByIdT(transactionId) } @@ -53,10 +45,10 @@ struct P2pAcceptDone: View { _ = try await model.confirmPeerPullDebitM(transactionId) } finished = true - playSound(success: true, incoming: incoming) + GNU_Taler.playSound( incoming ? 2 : 1) } catch { // TODO: error symLog.log(error.localizedDescription) - playSound(success: false, incoming: incoming) + GNU_Taler.playSound(0) } } } diff --git a/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift b/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift @@ -48,9 +48,11 @@ struct WithdrawAcceptDone: View { let result = try await model.sendAcceptIntWithdrawalM(exchangeBaseUrl, withdrawURL: url.absoluteString) confirmTransferUrl = result!.confirmTransferUrl transactionId = result!.transactionId + GNU_Taler.playSound(2) } } catch { // TODO: error symLog.log(error.localizedDescription) + GNU_Taler.playSound(0) } } }