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 { // 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. 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), let id = json["developmentTeam"], !id.isEmpty, id != "YOUR_10_CHAR_TEAM_ID" else { return fromDefaults } return id }