From da29f92c91ba86f79abf678d54a35f673244b0ab Mon Sep 17 00:00:00 2001 From: david-swift Date: Wed, 3 Jan 2024 09:27:22 +0100 Subject: [PATCH] Save state in the XDG data home directory --- Package.swift | 2 +- Sources/Adwaita/Model/Data Flow/State.swift | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 375244e..d5c97f3 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/AparokshaUI/Libadwaita", from: "0.1.0"), + .package(url: "https://github.com/AparokshaUI/Libadwaita", from: "0.1.5"), .package( url: "https://github.com/david-swift/LevenshteinTransformations", from: "0.1.1" diff --git a/Sources/Adwaita/Model/Data Flow/State.swift b/Sources/Adwaita/Model/Data Flow/State.swift index 090dcea..9f1d5f7 100644 --- a/Sources/Adwaita/Model/Data Flow/State.swift +++ b/Sources/Adwaita/Model/Data Flow/State.swift @@ -6,6 +6,7 @@ // import Foundation +import Libadwaita /// A property wrapper for properties in a view that should be stored throughout view updates. @propertyWrapper @@ -109,14 +110,14 @@ public struct State: StateProtocol { /// Get the settings directory path. /// - Returns: The path. - private func dirPath() -> String { - "\(NSHomeDirectory())/.config/\(GTUIApp.appID)/" + private func dirPath() -> URL { + NativePeer.getUserDataDirectory().appendingPathComponent(GTUIApp.appID, isDirectory: true) } /// Get the settings file path. /// - Returns: The path. private func filePath() -> URL { - .init(fileURLWithPath: dirPath() + "\(content.storage.key ?? "temporary").json") + dirPath().appendingPathComponent("\(content.storage.key ?? "temporary").json") } } @@ -138,9 +139,9 @@ extension State where Value: Codable { /// Check whether the settings file exists, and, if not, create it. private func checkFile() { let fileManager = FileManager.default - if !fileManager.fileExists(atPath: dirPath()) { + if !fileManager.fileExists(atPath: dirPath().path) { try? fileManager.createDirectory( - at: .init(fileURLWithPath: dirPath()), + at: .init(fileURLWithPath: dirPath().path), withIntermediateDirectories: true, attributes: nil )