2026-04-12 00:46:30 -07:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
struct SavedProject: Identifiable, Codable {
|
|
|
|
|
let id: UUID
|
|
|
|
|
var name: String
|
|
|
|
|
var rootPath: String
|
|
|
|
|
var scheme: String
|
|
|
|
|
var workingCopyRepoName: String
|
|
|
|
|
var bundleIdentifier: String
|
|
|
|
|
|
|
|
|
|
init(id: UUID = UUID(), name: String, rootPath: String, scheme: String,
|
|
|
|
|
workingCopyRepoName: String = "", bundleIdentifier: String = "") {
|
|
|
|
|
self.id = id; self.name = name; self.rootPath = rootPath
|
|
|
|
|
self.scheme = scheme; self.workingCopyRepoName = workingCopyRepoName
|
|
|
|
|
self.bundleIdentifier = bundleIdentifier
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 22:07:35 -07:00
|
|
|
@MainActor
|
2026-04-12 00:46:30 -07:00
|
|
|
final class ProjectStore: ObservableObject {
|
|
|
|
|
@Published var projects: [SavedProject] = [] { didSet { persist() } }
|
|
|
|
|
private let key = "padxcode.projects"
|
|
|
|
|
init() { load() }
|
|
|
|
|
func add(_ p: SavedProject) { projects.append(p) }
|
|
|
|
|
func remove(id: UUID) { projects.removeAll { $0.id == id } }
|
|
|
|
|
func remove(atOffsets o: IndexSet) { projects.remove(atOffsets: o) }
|
|
|
|
|
private func persist() {
|
|
|
|
|
if let d = try? JSONEncoder().encode(projects) { UserDefaults.standard.set(d, forKey: key) }
|
|
|
|
|
}
|
|
|
|
|
private func load() {
|
|
|
|
|
guard let d = UserDefaults.standard.data(forKey: key),
|
|
|
|
|
let v = try? JSONDecoder().decode([SavedProject].self, from: d) else { return }
|
|
|
|
|
projects = v
|
|
|
|
|
}
|
|
|
|
|
}
|