taler-ios

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

AboutView.swift (6941B)


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