taler-ios

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

commit 6c25aed49233d09fb701d661417381815596388b
parent 56615368eef6c33baa14c99582b579367836b6bb
Author: Marc Stibane <marc@taler.net>
Date:   Tue, 22 Aug 2023 17:12:33 +0200

Use sqlite3

Diffstat:
MTalerWallet1/Controllers/Controller.swift | 4++--
MTalerWallet1/Controllers/TalerWallet1App.swift | 3++-
MTalerWallet1/Model/WalletModel.swift | 8++++----
3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -43,12 +43,12 @@ class Controller: ObservableObject { } @MainActor - func initWalletCore(_ model: WalletModel) + func initWalletCore(_ model: WalletModel, sqlite3: Bool) async throws { if backendState == .instantiated { backendState = .initing do { - let versionInfo = try await model.initWalletCoreT() + let versionInfo = try await model.initWalletCoreT(sqlite3: sqlite3) WalletCore.shared.versionInfo = versionInfo backendState = .ready // dismiss the launch animation } catch { // rethrows diff --git a/TalerWallet1/Controllers/TalerWallet1App.swift b/TalerWallet1/Controllers/TalerWallet1App.swift @@ -27,6 +27,7 @@ struct TalerWallet1App: App { private let model = WalletModel.shared private let debugViewC = DebugViewC.shared let logger = Logger (subsystem: "net.taler.gnu", category: "Main App") + let sqlite3 = true // true = SQLITE3, false = JSON func scheduleAppRefresh() { let request = BGAppRefreshTaskRequest(identifier: "net.taler.gnu.refresh") @@ -45,7 +46,7 @@ struct TalerWallet1App: App { /// we handle them in .onOpenURL in MainView.swift .handlesExternalEvents(preferring: ["*"], allowing: ["*"]) .task { - try! await controller.initWalletCore(model) // will (and should) crash on failure + try! await controller.initWalletCore(model, sqlite3: sqlite3) // will (and should) crash on failure } .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification, object: nil)) { _ in logger.log("❗️App Did Become Active") diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift @@ -101,20 +101,20 @@ fileprivate struct InitRequest: WalletBackendFormattedRequest { extension WalletModel { /// initalize Wallet-Core. Will do networking - func initWalletCoreT() async throws -> VersionInfo { + func initWalletCoreT(sqlite3: Bool) async throws -> VersionInfo { // T for any Thread - let docPath = try docPath() + let docPath = try docPath(sqlite3: sqlite3) let request = InitRequest(persistentStoragePath: docPath) let response = try await sendRequest(request, 0) // no Delay return response.versionInfo } - private func docPath () throws -> String { + private func docPath (sqlite3: Bool) throws -> String { let documentUrls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) if (documentUrls.count > 0) { var storageDir = documentUrls[0] storageDir.appendPathComponent(DATABASE, isDirectory: false) - storageDir.appendPathExtension("json") + storageDir.appendPathExtension(sqlite3 ? "sqlite3" : "json") let docPath = storageDir.path logger.debug("\(docPath)") return docPath