taler-ios

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

AboutView.swift (6132B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import taler_swift
     10 import SymLog
     11 
     12 struct AboutView: View {
     13     private let symLog = SymLogV(0)
     14     let stack: CallStack
     15     let navTitle: String
     16 
     17     @EnvironmentObject private var controller: Controller
     18 #if DEBUG
     19     @AppStorage("developerMode") var developerMode: Bool = true
     20 #else
     21     @AppStorage("developerMode") var developerMode: Bool = false
     22 #endif
     23     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
     24     @AppStorage("minimalistic") var minimalistic: Bool = false
     25     @AppStorage("tapped") var tapped: Int = 0
     26     @AppStorage("dragged") var dragged: Int = 0
     27 
     28     @State private var rotationEnabled = false
     29     @State private var showGitHash = false
     30     @State private var listID = UUID()
     31     @State private var onboarding = false
     32 
     33     var body: some View {
     34 #if PRINT_CHANGES
     35         let _ = Self._printChanges()
     36         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     37 #endif
     38         let walletCore = WalletCore.shared
     39         let size = 100.0
     40         let rotatingTaler = RotatingTaler(size: size,
     41                                       progress: false,
     42                                rotationEnabled: $rotationEnabled)
     43             .accessibilityHidden(true)   // has its own accessibilityLabel
     44             .frame(maxWidth: .infinity, alignment: .center)
     45             .onTapGesture(count: 1) { rotationEnabled.toggle() }
     46         Group {
     47             List {
     48                 if #available(iOS 17.7, *) {
     49                     let talerURI = TALER_NET
     50                     BorderWithHCE(talerURI: talerURI, nfcHint: false, size: size, scanHints: nil) {
     51                         rotatingTaler
     52                     }
     53                 } else {
     54                     rotatingTaler
     55                 }
     56                 SettingsItem(name: String(localized: "Visit the taler.net website"),
     57                               id1: "web",
     58                         imageName: "link",
     59                       description: minimalistic ? nil : String(localized: "More info about GNU Taler in general...")) { }
     60                     .accessibilityAddTraits(.isLink)
     61                     .accessibilityRemoveTraits(.isStaticText)
     62                     .onTapGesture() {
     63                         UIApplication.shared.open(URL(string:TALER_NET)!, options: [:])
     64                     }
     65 
     66                 SettingsItem(name: String(localized: "App Version"), id1: "app") {
     67                     Text(verbatim: "\(Bundle.main.releaseVersionNumberPretty)")
     68                 }
     69                 Group {
     70                     if showGitHash {
     71                         SettingsItem(name: "Wallet-Core Git", id1: "wallet-coreG") {
     72                             if let gitHash = walletCore.versionInfo?.implementationGitHash {
     73                                 let index = gitHash.index(gitHash.startIndex, offsetBy: 7)
     74                                 Text(gitHash[..<index])
     75                             } else {
     76                                 Text(verbatim: "unknown")
     77                             }
     78                         }
     79                     } else {
     80                         SettingsItem(name: String(localized: "Wallet-Core Version"), id1: "wallet-coreV") {
     81                             Text(verbatim: "\(walletCore.versionInfo?.implementationSemver ?? "unknown")")
     82                         }
     83                     }
     84                 }.onTapGesture(count: 1) { showGitHash.toggle() }
     85                 SettingsToggle(name: String(localized: "Onboarding"),
     86                                value: $onboarding.onChange({ shouldOnboard in
     87                                     if shouldOnboard {
     88                                         tapped = 0
     89                                         dragged = 0
     90                                     } else {
     91                                         tapped = TAPPED
     92                                         dragged = DRAGGED
     93                                     }
     94                                 }),
     95                                 id1: "onboarding",
     96                         description: minimalistic ? nil : String(localized: "Explain the Actions button"))
     97 #if DEBUG
     98                 Text(verbatim: "Tapped: \(tapped), dragged: \(dragged)")
     99 #endif
    100 
    101 //                SettingsItem(name: "Supported Exchange Versions", id1: "exchange") {
    102 //                    Text(verbatim: "\(walletCore.versionInfo?.exchange ?? "unknown")")
    103 //                }
    104 //                SettingsItem(name: "Supported Merchant Versions", id1: "merchant") {
    105 //                    Text(verbatim: "\(walletCore.versionInfo?.merchant ?? "unknown")")
    106 //                }
    107 //                SettingsItem(name: "Used Bank", id1: "bank") {
    108 //                    Text(verbatim: "\(walletCore.versionInfo?.bank ?? "unknown")")
    109 //                }
    110             }
    111             .id(listID)
    112             .listStyle(myListStyle.style).anyView
    113         }
    114         .navigationTitle(navTitle)
    115         .task {
    116             onboarding = (tapped < TAPPED || dragged < DRAGGED)
    117 //            try? await Task.sleep(nanoseconds: 1_000_000_000 * UInt64(5))
    118 //            rotationEnabled.toggle()
    119         }
    120         .onAppear() {
    121             DebugViewC.shared.setViewID(VIEW_ABOUT, stack: stack.push())
    122         }
    123     }
    124 }
    125 extension Bundle {
    126     var bundleName: String? {
    127         return infoDictionary?["CFBundleDisplayName"] as? String
    128     }
    129     var releaseVersionNumber: String? {
    130         return infoDictionary?["CFBundleShortVersionString"] as? String
    131     }
    132     var buildVersionNumber: String {
    133         let build = infoDictionary?["CFBundleVersion"]
    134         let zero = "0"
    135         if let build {
    136             return build as? String ?? zero
    137         }
    138         return zero
    139     }
    140     var releaseVersionNumberPretty: String {
    141         let release = releaseVersionNumber ?? "1.0.0"
    142         return release // "v\(release) (\(buildVersionNumber))"
    143     }
    144 }
    145 // MARK: -
    146 #if DEBUG
    147 struct AboutView_Previews: PreviewProvider {
    148     static var previews: some View {
    149         AboutView(stack: CallStack("Preview"), navTitle: "About")
    150     }
    151 }
    152 #endif