commit 551285dced3b70bb173b1d8e3a31f162eb7da30e
parent 7d32de822929ea1b846d6447cf8316c35031b9fc
Author: Marc Stibane <marc@taler.net>
Date: Tue, 5 Sep 2023 18:37:13 +0200
Haptics
Diffstat:
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift
@@ -7,6 +7,7 @@ import AVFoundation
import SwiftUI
import SymLog
import os.log
+import CoreHaptics
enum BackendState {
case none
@@ -32,8 +33,10 @@ class Controller: ObservableObject {
private let symLog = SymLogC()
@Published var backendState: BackendState = .none // only used for launch animation
+ @AppStorage("useHaptics") var useHaptics: Bool = false // extension mustn't define this, so it must be here
@AppStorage("playSounds") var playSounds: Int = 0 // extension mustn't define this, so it must be here
@AppStorage("talerFont") var talerFont: Int = 0 // extension mustn't define this, so it must be here
+ let hapticCapability = CHHapticEngine.capabilitiesForHardware()
let logger = Logger (subsystem: "net.taler.gnu", category: "Controller")
let player = AVQueuePlayer()
diff --git a/TalerWallet1/Helper/Controller+playSound.swift b/TalerWallet1/Helper/Controller+playSound.swift
@@ -4,12 +4,14 @@
*/
import Foundation
import AVFoundation
+import UIKit
extension Controller {
/// 0 = failure, 1 = received, 2 = sent
func playSound(_ number: Int) {
var soundID: SystemSoundID = 0
+ let notificationGenerator = useHaptics ? UINotificationFeedbackGenerator() : nil
if number > 9 {
soundID = UInt32(number)
} else {
@@ -34,5 +36,8 @@ extension Controller {
AudioServicesPlaySystemSound(soundID);
}
}
+ if let notificationGenerator {
+ notificationGenerator.notificationOccurred(number == 0 ? .error : .success)
+ }
}
}
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -21,11 +21,13 @@ struct SettingsView: View {
private let symLog = SymLogV(0)
let navTitle: String
+ @EnvironmentObject private var controller: Controller
#if DEBUG
@AppStorage("developerMode") var developerMode: Bool = true
#else
@AppStorage("developerMode") var developerMode: Bool = false
#endif
+ @AppStorage("useHaptics") var useHaptics: Bool = false
@AppStorage("playSounds") var playSounds: Int = 0
@AppStorage("talerFont") var talerFont: Int = 0
@AppStorage("developDelay") var developDelay: Bool = false
@@ -81,8 +83,12 @@ struct SettingsView: View {
let walletCore = WalletCore.shared
Group {
List {
+ if controller.hapticCapability.supportsHaptics {
+ SettingsToggle(name: String(localized: "Haptics"), value: $useHaptics,
+ description: String(localized: "Vibration Feedback"))
+ }
SettingsSpeaker(name: String(localized: "Play Payment Sounds"), value: $playSounds,
- description: String(localized: "After a transaction finished"))
+ description: String(localized: "When a transaction finished"))
SettingsFont(title: String(localized: "Font:"), value: talerFont, action: redraw)
SettingsStyle(title: String(localized: "Liststyle:"), myListStyle: $myListStyle)
if diagnosticModeEnabled {