commit 974db16a4d1e153415d77bb6d97817ee799abb4d
parent a68b2d272754e36399f818a71f8002702aba7a35
Author: Marc Stibane <marc@taler.net>
Date: Fri, 30 Jun 2023 20:06:11 +0200
playSound
Diffstat:
9 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift
@@ -190,7 +190,7 @@ extension WalletCore {
let components = decoded.transactionId.components(separatedBy: [":"])
if components.count >= 3 { // txn:$txtype:$uid
if let type = TransactionType(rawValue: components[1]) {
- playSound(type.isIncoming ? 2 : 1)
+ Controller.shared.playSound(type.isIncoming ? 2 : 1)
}
}
}
diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift
@@ -28,6 +28,7 @@ class Controller: ObservableObject {
private let symLog = SymLogC()
@Published var backendState: BackendState = .none // only used for launch animation
+ @AppStorage("playSounds") var playSounds: Bool = false
var messageForSheet: String? = nil
diff --git a/TalerWallet1/Helper/playSound.swift b/TalerWallet1/Helper/playSound.swift
@@ -5,16 +5,21 @@
import Foundation
import AVFoundation
-func playSound(_ number: Int) {
- var soundID: SystemSoundID = 0
- if number < 999 {
- let sound = (number == 0) ? "payment_failure" :
- (number == 1) ? "payment_success" : "PaymentReceived"
- let fileURL = URL(fileURLWithPath: "/System/Library/Audio/UISounds/"
- + sound + ".caf")
- AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID)
- } else {
- soundID = UInt32(number)
+extension Controller {
+
+ func playSound(_ number: Int) {
+ var soundID: SystemSoundID = 0
+ if number < 999 {
+ let sound = (number == 0) ? "payment_failure" :
+ (number == 1) ? "payment_success" : "PaymentReceived"
+ let fileURL = URL(fileURLWithPath: "/System/Library/Audio/UISounds/"
+ + sound + ".caf")
+ AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID)
+ } else {
+ soundID = UInt32(number)
+ }
+ if playSounds {
+ AudioServicesPlaySystemSound(soundID);
+ }
}
- AudioServicesPlaySystemSound(soundID);
}
diff --git a/TalerWallet1/Views/HelperViews/Buttons.swift b/TalerWallet1/Views/HelperViews/Buttons.swift
@@ -191,32 +191,32 @@ struct Buttons_Previews: PreviewProvider {
static var previews: some View {
VStack {
HamburgerButton() {
- playSound(1000)
+ Controller.shared.playSound(1000)
}.padding()
QRButton() {
- playSound(1001)
+ Controller.shared.playSound(1001)
}.padding()
PlusButton() {
- playSound(1002) // == 7
+ Controller.shared.playSound(1002) // == 7
}.padding()
HamburgerButton() {
- playSound(1003)
+ Controller.shared.playSound(1003)
}.padding()
QRButton() {
- playSound(1004)
+ Controller.shared.playSound(1004)
}.padding()
PlusButton() {
- playSound(1005)
+ Controller.shared.playSound(1005)
}.padding()
HStack {
ReloadButton(disabled: false) {
- playSound(1006)
+ Controller.shared.playSound(1006)
}.padding()
ReloadButton(disabled: true) {
}.padding()
}
Button(String(localized: "Accept"), action: {
- playSound(1008)
+ Controller.shared.playSound(1008)
})
.buttonStyle(TalerButtonStyle(type: .prominent))
.padding(.horizontal)
diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift
@@ -35,7 +35,7 @@ struct MainView: View {
// any change to rootViewId triggers popToRootView behaviour
.id(viewState.rootViewId)
.onAppear() {
- GNU_Taler.playSound(1008) // TODO: Startup chime
+ controller.playSound(1008) // TODO: Startup chime
soundPlayed = true
}
} else if controller.backendState == .error {
diff --git a/TalerWallet1/Views/Payment/PaymentURIView.swift b/TalerWallet1/Views/Payment/PaymentURIView.swift
@@ -12,6 +12,8 @@ struct PaymentURIView: View {
private let symLog = SymLogV()
let navTitle = String(localized: "Confirm Payment", comment:"pay merchant")
+ @EnvironmentObject private var controller: Controller
+
// the scanned URL
let url: URL
@@ -23,11 +25,11 @@ struct PaymentURIView: View {
let confirmPayResult = try await model.confirmPayM(detailsForUri.proposalId)
symLog.log(confirmPayResult as Any)
if confirmPayResult.type != "done" {
- GNU_Taler.playSound(0)
+ controller.playSound(0)
// TODO: show error
}
} catch {
- GNU_Taler.playSound(0)
+ controller.playSound(0)
// TODO: error
symLog.log(error.localizedDescription)
}
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -26,6 +26,7 @@ struct SettingsView: View {
#else
@AppStorage("developerMode") var developerMode: Bool = false
#endif
+ @AppStorage("playSounds") var playSounds: Bool = false
@AppStorage("developDelay") var developDelay: Bool = false
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
@@ -50,6 +51,8 @@ struct SettingsView: View {
let walletCore = WalletCore.shared
Group {
List {
+ SettingsToggle(name: String(localized: "Play Payment Sounds"), value: $playSounds,
+ description: String(localized: "After a transaction finished"))
HStack {
Text("Liststyle:")
.font(.title2)
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
@@ -13,6 +13,7 @@ struct P2pAcceptDone: View {
let incoming: Bool
@EnvironmentObject private var model: WalletModel
+ @EnvironmentObject private var controller: Controller
@State private var finished: Bool = false
@@ -48,7 +49,7 @@ struct P2pAcceptDone: View {
finished = true
} catch { // TODO: error
symLog.log(error.localizedDescription)
- GNU_Taler.playSound(0)
+ controller.playSound(0)
}
}
}
diff --git a/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift b/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift
@@ -14,6 +14,7 @@ struct WithdrawAcceptDone: View {
let url: URL
@EnvironmentObject private var model: WalletModel
+ @EnvironmentObject private var controller: Controller
@State private var transactionId: String? = nil
@@ -52,7 +53,7 @@ struct WithdrawAcceptDone: View {
}
} catch { // TODO: error
symLog.log(error.localizedDescription)
- GNU_Taler.playSound(0)
+ controller.playSound(0)
}
}
}