taler-ios

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

commit 5db5699c4c2e5a950a6ffb0806fe028c4345b5b5
parent b8fd9fc88b93981374267b78a7a8e37277a3b5a4
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 13 Apr 2024 07:05:00 +0200

Tri-State, less is more

Diffstat:
MTalerWallet1/Backend/WalletCore.swift | 39++++++++++++++++++++++-----------------
MTalerWallet1/Views/Settings/SettingsItem.swift | 14+++++++-------
MTalerWallet1/Views/Settings/SettingsView.swift | 4++--
3 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift @@ -302,18 +302,20 @@ extension WalletCore { case Notification.Name.ProposalDownloaded.rawValue: // "proposal-downloaded": symLog.log(anyPayload) postNotification(.ProposalDownloaded, userInfo: nil) - case Notification.Name.TaskObservabilityEvent.rawValue, Notification.Name.RequestObservabilityEvent.rawValue: + case Notification.Name.TaskObservabilityEvent.rawValue, + Notification.Name.RequestObservabilityEvent.rawValue: symLog.log(anyPayload) - let timestamp = TalerDater.dateString() - if let event = payload.event, - let json = event.toJSON(), - let type = event["type"]?.value as? String { - observe(json: json, - type: type, - timestamp: timestamp, - showJSON: isObserving < 0) + if isObserving != 0 { + let timestamp = TalerDater.dateString() + if let event = payload.event, let json = event.toJSON() { + let type = event["type"]?.value as? String + let eventID = event["id"]?.value as? String + observe(json: json, + type: type, + eventID: eventID, + timestamp: timestamp) + } } - // TODO: remove these once wallet-core doesn't send them anymore // case "refresh-started", "refresh-melted", // "refresh-revealed", "refresh-unwarranted": @@ -330,23 +332,26 @@ print("\n❗️ WalletCore.swift:251 Notification: ", anyPayload, "\n") / } @MainActor func handleLog(message: String) { - let consoleManager = LCManager.shared if isLogging { + let consoleManager = LCManager.shared consoleManager.print(message) } } - @MainActor func observe(json: String, type: String?, timestamp: String, showJSON: Bool) { + @MainActor func observe(json: String, type: String?, eventID: String?, timestamp: String) { let consoleManager = LCManager.shared if let type { - consoleManager.print("- Event type: \(type)") + if let eventID { + consoleManager.print("\(type) \(eventID)") + } else { + consoleManager.print(type) + } } - consoleManager.print("- Timestamp: \(timestamp)") - if showJSON{ - consoleManager.print("- Payload:") + consoleManager.print(" \(timestamp)") + if isObserving < 0 { consoleManager.print(json) } - consoleManager.print("------") + consoleManager.print("- - -") } /// here not only responses, but also notifications from wallet-core will be received diff --git a/TalerWallet1/Views/Settings/SettingsItem.swift b/TalerWallet1/Views/Settings/SettingsItem.swift @@ -130,16 +130,16 @@ struct SettingsStyle: View { } } // MARK: - -struct SettingsSpeaker: View { +struct SettingsTriState: View { var name: String @Binding var value: Int var description: String? var action: (_ value: Int) -> Void = {value in } func imageName(_ value: Int) -> (String, String) { - return (value == 0) ? ("speaker.slash", String(localized:"Off", comment: "Accessibility String for Payment Sounds.")) - : (value == 1) ? ("speaker.fill", String(localized:"Taler Sounds", comment: "Accessibility String for Payment Sounds.")) - : ("speaker", String(localized:"Apple Sounds", comment: "Accessibility String for Payment Sounds.")) + return (value == 0) ? ("eye.slash", "Off") + : (value == 1) ? ("eye", "Type only") + : ("eye.fill", "Type and JSON") } var body: some View { let image = imageName(value) @@ -185,14 +185,14 @@ struct SettingsSpeaker: View { #if DEBUG struct SettingsItemPreview : View { @State var developerMode: Bool = false - @State var playSounds: Int = 0 + @State var observe: Int = 0 var body: some View { VStack { SettingsToggle(name: "Developer Mode", value: $developerMode, id1: "dev1", description: "More information intended for debugging") - SettingsSpeaker(name: String(localized: "Play Payment Sounds"), value: $playSounds, - description: String(localized: "After a transaction finished")) + SettingsTriState(name: "Observe walletCore", value: $observe, + description: "on LocalConsole") } } diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift @@ -128,11 +128,11 @@ struct SettingsView: View { SettingsStyle(title: String(localized: "Liststyle:"), myListStyle: $myListStyle) .id("liststyle") let localConsStr = String(localized: "on LocalConsole") - let observability = String(localized: "Observability") + let observability = String(localized: "Observe walletCore") // SettingsToggle(name: observability, value: $localConsoleO.onChange({ isObserving in // walletCore.isObserving = isObserving}), id1: "localConsoleO", // description: hideDescriptions ? nil : localConsStr) { - SettingsSpeaker(name: observability, value: $localConsoleO.onChange({ isObserving in + SettingsTriState(name: observability, value: $localConsoleO.onChange({ isObserving in walletCore.isObserving = isObserving}), description: hideDescriptions ? nil : localConsStr) { isObserving in let consoleManager = LCManager.shared