PadXcode-Daemon/Daemon/Setup.swift

40 lines
2.2 KiB
Swift
Raw Permalink Normal View History

2026-04-12 00:42:51 -07:00
import Foundation
func ensureConfigFile() {
let dir = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent(".padxcode")
let file = dir.appendingPathComponent("config.json")
guard !FileManager.default.fileExists(atPath: file.path) else { return }
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
let defaults: [String: String] = [
"developmentTeam": "YOUR_10_CHAR_TEAM_ID",
"codeSignIdentity": "Apple Development",
"allowProvisioningUpdates": "true"
]
if let data = try? JSONEncoder().encode(defaults) { try? data.write(to: file) }
print("""
PadXcode Daemon First Run Setup
Config created: ~/.padxcode/config.json
Edit it and set your developmentTeam to your
10-character Apple Developer Team ID.
Find it at: developer.apple.com/account
""")
}
func loadTeamID() -> String {
2026-04-12 22:14:13 -07:00
// Prefer UserDefaults (set by Settings UI) over config file.
// This ensures changes made in the Settings window take effect immediately.
let fromDefaults = UserDefaults.standard.string(forKey: "developmentTeam") ?? ""
if !fromDefaults.isEmpty && fromDefaults != "YOUR_10_CHAR_TEAM_ID" { return fromDefaults }
// Fall back to ~/.padxcode/config.json for initial setup.
2026-04-12 00:42:51 -07:00
let file = "\(NSHomeDirectory())/.padxcode/config.json"
guard let data = try? Data(contentsOf: URL(fileURLWithPath: file)),
let json = try? JSONDecoder().decode([String: String].self, from: data),
2026-04-12 22:14:13 -07:00
let id = json["developmentTeam"],
!id.isEmpty, id != "YOUR_10_CHAR_TEAM_ID" else { return fromDefaults }
2026-04-12 00:42:51 -07:00
return id
}