39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
|
|
import Foundation
|
||
|
|
|
||
|
|
public struct SaplingConfiguration: Hashable, Codable, Sendable {
|
||
|
|
public var recentWorkspaceURLs: [URL]
|
||
|
|
public var defaultBranchName: String
|
||
|
|
public var autosavesDrafts: Bool
|
||
|
|
|
||
|
|
public init(
|
||
|
|
recentWorkspaceURLs: [URL] = [],
|
||
|
|
defaultBranchName: String = "main",
|
||
|
|
autosavesDrafts: Bool = true
|
||
|
|
) {
|
||
|
|
self.recentWorkspaceURLs = recentWorkspaceURLs
|
||
|
|
self.defaultBranchName = defaultBranchName
|
||
|
|
self.autosavesDrafts = autosavesDrafts
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public protocol ConfigurationStore: Sendable {
|
||
|
|
func loadConfiguration() throws -> SaplingConfiguration
|
||
|
|
func saveConfiguration(_ configuration: SaplingConfiguration) throws
|
||
|
|
}
|
||
|
|
|
||
|
|
public final class InMemoryConfigurationStore: ConfigurationStore, @unchecked Sendable {
|
||
|
|
private var configuration: SaplingConfiguration
|
||
|
|
|
||
|
|
public init(configuration: SaplingConfiguration = SaplingConfiguration()) {
|
||
|
|
self.configuration = configuration
|
||
|
|
}
|
||
|
|
|
||
|
|
public func loadConfiguration() throws -> SaplingConfiguration {
|
||
|
|
configuration
|
||
|
|
}
|
||
|
|
|
||
|
|
public func saveConfiguration(_ configuration: SaplingConfiguration) throws {
|
||
|
|
self.configuration = configuration
|
||
|
|
}
|
||
|
|
}
|