// Author: Simon-Pierre Boucher — contact@spboucher.ai // // Paths (forge binary, workspace) with live validation via `forge info`. import SwiftUI import UniformTypeIdentifiers struct SettingsView: View { @Environment(AppModel.self) private var app @State private var binaryPath = ForgeBinaryLocator.savedBinaryURL?.path ?? "" @State private var workspacePath = ForgeBinaryLocator.savedWorkspaceURL?.path ?? "" var body: some View { Form { Section("Binaire forge") { HStack { TextField("Chemin", text: $binaryPath) .font(.callout.monospaced()) Button("Choisir…") { pickBinary() } } if let device = app.forgeDevice { Label("Validé — \(device)", systemImage: "checkmark.circle.fill") .foregroundStyle(.green) } else if let error = app.forgeError { Label(error, systemImage: "xmark.circle.fill") .foregroundStyle(.red) } Button("Revalider") { ForgeBinaryLocator.save(binary: URL(fileURLWithPath: binaryPath)) Task { await app.validateForge() } } } Section("Espace de travail") { HStack { TextField("Dossier (runs/, data/)", text: $workspacePath) .font(.callout.monospaced()) Button("Choisir…") { pickWorkspace() } } Text("Runs : \(app.store.workspaceURL.path)/runs") .font(.caption) .foregroundStyle(.secondary) } } .formStyle(.grouped) .frame(width: 560, height: 320) } private func pickBinary() { let panel = NSOpenPanel() panel.allowedContentTypes = [.unixExecutable, .executable] panel.canChooseDirectories = false if panel.runModal() == .OK, let url = panel.url { binaryPath = url.path ForgeBinaryLocator.save(binary: url) Task { await app.validateForge() } } } private func pickWorkspace() { let panel = NSOpenPanel() panel.canChooseDirectories = true panel.canChooseFiles = false panel.canCreateDirectories = true if panel.runModal() == .OK, let url = panel.url { workspacePath = url.path ForgeBinaryLocator.save(workspace: url) } } }