Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

PersistentDirectory dependency

Kabir Oberai71a82d1e052e
diff --git a/Sources/Supersign/GrandSlam/Anisette/SupersetteADIProvider.swift b/Sources/Supersign/GrandSlam/Anisette/SupersetteADIProvider.swift
index c88f56f..d34989b 100644
--- a/Sources/Supersign/GrandSlam/Anisette/SupersetteADIProvider.swift
+++ b/Sources/Supersign/GrandSlam/Anisette/SupersetteADIProvider.swift
@@ -7,11 +7,11 @@ import Dependencies
public actor SupersetteADIProvider: RawADIProvider {
@MainActor private static var loadTask: Task<Void, Error>?
@Dependency(\.httpClient) private var httpClient
+ @Dependency(\.persistentDirectory) private var persistentDirectory
- public let directory: URL
- public init() {
- self.directory = URL.homeDirectory.appending(path: ".config/Supercharge/Anisette")
- }
+ private var directory: URL { persistentDirectory.appendingPathComponent("Anisette") }
+
+ public init() {}
private func _loadADI(id: UUID) async throws {
let dir = self.directory
diff --git a/Sources/Supersign/Utilities/DirectoryProvider.swift b/Sources/Supersign/Utilities/DirectoryProvider.swift
new file mode 100644
index 0000000..132f04d
--- /dev/null
+++ b/Sources/Supersign/Utilities/DirectoryProvider.swift
@@ -0,0 +1,18 @@
+import Foundation
+import Dependencies
+
+private struct PersistentDirectoryProvider: DependencyKey, Sendable {
+ var directory: URL
+
+ static let liveValue = PersistentDirectoryProvider(
+ directory: URL(fileURLWithPath: NSHomeDirectory())
+ .appendingPathComponent(".config/Supercharge")
+ )
+}
+
+extension DependencyValues {
+ public var persistentDirectory: URL {
+ get { self[PersistentDirectoryProvider.self].directory }
+ set { self[PersistentDirectoryProvider.self].directory = newValue }
+ }
+}
diff --git a/Sources/Supersign/Utilities/KeyValueStorage.swift b/Sources/Supersign/Utilities/KeyValueStorage.swift
index d3a53f9..6d20fa5 100644
--- a/Sources/Supersign/Utilities/KeyValueStorage.swift
+++ b/Sources/Supersign/Utilities/KeyValueStorage.swift
@@ -82,10 +82,11 @@ public final class MemoryKeyValueStorage: KeyValueStorage {
}
public struct DirectoryStorage: KeyValueStorage {
- let base: URL
- public init(base: URL) {
- self.base = base
- }
+ @Dependency(\.persistentDirectory) var directory
+
+ private var base: URL { directory.appendingPathComponent("data") }
+
+ public init() {}
private func url(for key: String) -> URL {
base.appendingPathComponent(key)
diff --git a/Sources/SupersignCLI/SupersignCLI.swift b/Sources/SupersignCLI/SupersignCLI.swift
index 43052a4..3475bf0 100644
--- a/Sources/SupersignCLI/SupersignCLI.swift
+++ b/Sources/SupersignCLI/SupersignCLI.swift
@@ -20,9 +20,7 @@ extension KeyValueStorageDependencyKey: DependencyKey {
// #if os(macOS)
// KeychainStorage(service: "com.kabiroberai.Supercharge-Keychain.credentials")
// #else
- DirectoryStorage(
- base: URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent(".config/Supercharge/data")
- )
+ DirectoryStorage()
// #endif
}()
}