From 0a6f1043b94955a7858a60bb8589a983666772e2 Mon Sep 17 00:00:00 2001 From: david-swift Date: Fri, 4 Oct 2024 01:03:57 +0200 Subject: [PATCH] Add meta-sqlite to adwaita-swift --- Package.swift | 4 +++- Sources/Adwaita/Model/AdwaitaApp.swift | 9 +++++++++ Sources/Demo/CounterDemo.swift | 3 ++- Sources/Demo/Demo.swift | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 336c978..2bba102 100644 --- a/Package.swift +++ b/Package.swift @@ -24,6 +24,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/AparokshaUI/Meta", branch: "main"), + .package(url: "https://github.com/AparokshaUI/meta-sqlite", branch: "main"), .package( url: "https://github.com/david-swift/LevenshteinTransformations", from: "0.1.1" @@ -40,7 +41,8 @@ let package = Package( dependencies: [ "CAdw", .product(name: "LevenshteinTransformations", package: "LevenshteinTransformations"), - .product(name: "Meta", package: "Meta") + .product(name: "Meta", package: "Meta"), + .product(name: "MetaSQLite", package: "meta-sqlite") ] ), .executableTarget( diff --git a/Sources/Adwaita/Model/AdwaitaApp.swift b/Sources/Adwaita/Model/AdwaitaApp.swift index 1718db8..cd9fc74 100644 --- a/Sources/Adwaita/Model/AdwaitaApp.swift +++ b/Sources/Adwaita/Model/AdwaitaApp.swift @@ -6,7 +6,9 @@ // import CAdw +import Foundation @_exported import Meta +@_exported import MetaSQLite /// The Meta app storage for the Adwaita backend. public class AdwaitaApp: AppStorage { @@ -31,6 +33,7 @@ public class AdwaitaApp: AppStorage { /// - Parameter id: The identifier. public required init(id: String) { pointer = adw_application_new(id, G_APPLICATION_DEFAULT_FLAGS)?.cast() + DatabaseInformation.setPath(Self.userDataDir().appendingPathComponent("data.sqlite").path) } /// Copy a string to the clipboard. @@ -39,6 +42,12 @@ public class AdwaitaApp: AppStorage { gdk_clipboard_set_text(clipboard, text) } + /// The directory used for storing user data. + /// - Returns: The URL. + public static func userDataDir() -> URL { + .init(fileURLWithPath: .init(cString: g_get_user_data_dir())) + } + /// Execute the app. /// - Parameter setup: Set the scene elements up. public func run(setup: @escaping () -> Void) { diff --git a/Sources/Demo/CounterDemo.swift b/Sources/Demo/CounterDemo.swift index 1e86722..5599683 100644 --- a/Sources/Demo/CounterDemo.swift +++ b/Sources/Demo/CounterDemo.swift @@ -11,7 +11,8 @@ import Adwaita struct CounterDemo: View { - @State private var count = 0 + @State("count") + private var count = 0 var view: Body { VStack { diff --git a/Sources/Demo/Demo.swift b/Sources/Demo/Demo.swift index a802c91..a0bb33d 100644 --- a/Sources/Demo/Demo.swift +++ b/Sources/Demo/Demo.swift @@ -68,7 +68,8 @@ struct Demo: App { struct DemoContent: WindowView { - @State private var selection: Page = .welcome + @State("selection") + private var selection: Page = .welcome @State private var toast: Signal = .init() @State private var sidebarVisible = true @State private var width = 650