forked from aparoksha/adwaita-swift
Save state in the XDG data home directory
This commit is contained in:
parent
021f0f231f
commit
da29f92c91
@ -18,7 +18,7 @@ let package = Package(
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/AparokshaUI/Libadwaita", from: "0.1.0"),
|
.package(url: "https://github.com/AparokshaUI/Libadwaita", from: "0.1.5"),
|
||||||
.package(
|
.package(
|
||||||
url: "https://github.com/david-swift/LevenshteinTransformations",
|
url: "https://github.com/david-swift/LevenshteinTransformations",
|
||||||
from: "0.1.1"
|
from: "0.1.1"
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Libadwaita
|
||||||
|
|
||||||
/// A property wrapper for properties in a view that should be stored throughout view updates.
|
/// A property wrapper for properties in a view that should be stored throughout view updates.
|
||||||
@propertyWrapper
|
@propertyWrapper
|
||||||
@ -109,14 +110,14 @@ public struct State<Value>: StateProtocol {
|
|||||||
|
|
||||||
/// Get the settings directory path.
|
/// Get the settings directory path.
|
||||||
/// - Returns: The path.
|
/// - Returns: The path.
|
||||||
private func dirPath() -> String {
|
private func dirPath() -> URL {
|
||||||
"\(NSHomeDirectory())/.config/\(GTUIApp.appID)/"
|
NativePeer.getUserDataDirectory().appendingPathComponent(GTUIApp.appID, isDirectory: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the settings file path.
|
/// Get the settings file path.
|
||||||
/// - Returns: The path.
|
/// - Returns: The path.
|
||||||
private func filePath() -> URL {
|
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.
|
/// Check whether the settings file exists, and, if not, create it.
|
||||||
private func checkFile() {
|
private func checkFile() {
|
||||||
let fileManager = FileManager.default
|
let fileManager = FileManager.default
|
||||||
if !fileManager.fileExists(atPath: dirPath()) {
|
if !fileManager.fileExists(atPath: dirPath().path) {
|
||||||
try? fileManager.createDirectory(
|
try? fileManager.createDirectory(
|
||||||
at: .init(fileURLWithPath: dirPath()),
|
at: .init(fileURLWithPath: dirPath().path),
|
||||||
withIntermediateDirectories: true,
|
withIntermediateDirectories: true,
|
||||||
attributes: nil
|
attributes: nil
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user