import SwiftUI import LichtkastenCore /// Own settings navigation (Apple's settings tab bar always uses the system accent color). struct SettingsView: View { enum Page: String, CaseIterable, Identifiable { case general = "Allgemein", ftp = "FTP", immich = "Immich", lightroom = "Lightroom", codes = "Codes" var id: String { rawValue } var icon: String { switch self { case .general: return "gearshape" case .ftp: return "server.rack" case .immich: return "photo.stack" case .lightroom: return "camera.aperture" case .codes: return "character.textbox" } } } @AppStorage("settingsPage") private var page: Page = .general var body: some View { HStack(spacing: 0) { VStack(alignment: .leading, spacing: 4) { LKSectionLabel(title: "Einstellungen").padding(.horizontal, 10).padding(.bottom, 8) ForEach(Page.allCases) { p in let on = p == page Button { page = p } label: { HStack(spacing: 10) { Image(systemName: p.icon).frame(width: 18) Text(p.rawValue).font(.system(size: 13, weight: on ? .bold : .medium)) Spacer() } .foregroundStyle(on ? LK.amber : LK.text) .padding(.horizontal, 10) .frame(height: 32) .background(RoundedRectangle(cornerRadius: 8).fill(on ? LK.selected : Color.clear)) .contentShape(Rectangle()) } .buttonStyle(.plain) } Spacer() } .padding(14) .frame(width: 190) .background(LK.panel) Rectangle().fill(LK.border).frame(width: 1) Group { switch page { case .general: GeneralSettings() case .ftp: FTPSettings() case .immich: ImmichSettingsView() case .lightroom: LightroomSettingsView() case .codes: CodesSettings() } } .frame(maxWidth: .infinity, maxHeight: .infinity) } .background(LK.ground) .navigationTitle(page.rawValue) } } struct GeneralSettings: View { @EnvironmentObject var state: AppState var body: some View { Form { Section("Tastatur") { Picker("Belegung", selection: $state.settings.keyScheme) { ForEach(KeyScheme.allCases, id: \.self) { Text($0.title).tag($0) } } Toggle("Nach Bewertung/Tag automatisch zum nächsten Bild", isOn: $state.settings.autoAdvance) Text("1–8 = Farbklasse · 0 = keine · ⌥1–5 = Sterne · T = Tag · I = IPTC-Info · ⌘I = IPTC für Auswahl · ⌘U = Hochladen · ⌘E = Lightroom · ⌘⌥S = INPUT ⇄ SENT") .font(.caption).foregroundStyle(.secondary) } Section("Zoom") { Picker("Maximaler Zoom in der Vorschau", selection: $state.settings.maxZoom) { Text("100 %").tag(1.0); Text("200 %").tag(2.0); Text("400 %").tag(4.0); Text("800 %").tag(8.0); Text("1600 %").tag(16.0) } Slider(value: $state.settings.maxThumbnailSize, in: 300...1200, step: 50) { Text("Größte Vorschaubilder: \(Int(state.settings.maxThumbnailSize)) px") } Text("Vorschau: Z = Einpassen/100 %, + / − oder Trackpad zum Zoomen.").font(.caption).foregroundStyle(.secondary) } Section("Ansicht") { Toggle("Matchday-Ansicht (Teamleiste, Spieler:innen-Liste, Teamfarben)", isOn: $state.settings.jersey.matchday) if state.settings.jersey.matchday && state.settings.jersey.teams.count < 2 { Text("Braucht zwei Teams in Bild → Trikot-Erkennung einrichten.").font(.caption).foregroundStyle(.secondary) } Toggle("IPTC-Panel neben der Vorschau", isOn: $state.settings.loupePanel) } Section("Ingest") { Toggle("Ingest-Fenster öffnen, wenn eine Speicherkarte erkannt wird", isOn: $state.settings.autoIngestOnCardMount) Toggle("Karte nach dem Ingest automatisch auswerfen", isOn: $state.settings.ingest.unmountAfter) } Section("exiftool") { HStack { TextField("Pfad (leer = automatisch)", text: $state.settings.exiftoolPath) Button("Neu verbinden") { state.resetExifTool() } } if let url = ExifTool.locate(custom: state.settings.exiftoolPath) { Label("Gefunden: \(url.path)", systemImage: "checkmark.circle.fill").foregroundStyle(.green) } else { Label("Nicht gefunden – Terminal: brew install exiftool", systemImage: "xmark.octagon.fill").foregroundStyle(.red) } } Section("Variablen") { TextField("Datumsformat für {date}", text: $state.settings.dateFormat) Text("z. B. dd.MM.yyyy → 03.11.2026 · d. MMMM yyyy → 3. November 2026") .font(.caption).foregroundStyle(.secondary) } } .lkForm() } } struct FTPSettings: View { @EnvironmentObject var state: AppState @State private var selected: UUID? @State private var password = "" @State private var testResult = "" @State private var testing = false private var index: Int? { state.settings.ftpDestinations.firstIndex { $0.id == selected } } var body: some View { HSplitView { VStack(spacing: 0) { List(selection: $selected) { ForEach(state.settings.ftpDestinations) { d in Text(d.name).tag(d.id) } }.scrollContentBackground(.hidden).background(LK.deep) HStack { Button { let d = FTPDestination(); state.settings.ftpDestinations.append(d); selected = d.id } label: { Image(systemName: "plus") } Button { if let i = index { Keychain.set("", account: state.settings.ftpDestinations[i].keychainAccount) state.settings.ftpDestinations.remove(at: i); selected = nil } } label: { Image(systemName: "minus") }.disabled(index == nil) Spacer() } .buttonStyle(.borderless).padding(6) } .frame(minWidth: 170, maxWidth: 220) if let i = index { Form { TextField("Name", text: $state.settings.ftpDestinations[i].name) Picker("Protokoll", selection: Binding( get: { state.settings.ftpDestinations[i].proto }, set: { p in state.settings.ftpDestinations[i].proto = p state.settings.ftpDestinations[i].port = p.defaultPort })) { ForEach(FTPProtocol.allCases, id: \.self) { Text($0.rawValue).tag($0) } } TextField("Server", text: $state.settings.ftpDestinations[i].host) TextField("Port", value: $state.settings.ftpDestinations[i].port, format: .number.grouping(.never)) TextField("Benutzer", text: $state.settings.ftpDestinations[i].username) SecureField("Passwort (Schlüsselbund)", text: $password) .onSubmit { Keychain.set(password, account: state.settings.ftpDestinations[i].keychainAccount) } .onChange(of: password) { _, p in Keychain.set(p, account: state.settings.ftpDestinations[i].keychainAccount) } if state.settings.ftpDestinations[i].proto == .sftp { TextField("SSH-Schlüssel (optional)", text: $state.settings.ftpDestinations[i].sshKeyPath) } TextField("Zielordner", text: $state.settings.ftpDestinations[i].remoteDirectory) Picker("Dateien", selection: $state.settings.ftpDestinations[i].variant) { ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) } } TextField("Umbenennen (leer = Originalname)", text: $state.settings.ftpDestinations[i].renamePattern) Toggle("Passiver Modus", isOn: $state.settings.ftpDestinations[i].passive) Toggle("Mit .part hochladen und danach umbenennen", isOn: $state.settings.ftpDestinations[i].uploadWithTempName) Toggle("TLS-Zertifikat nicht prüfen (nur wenn nötig)", isOn: $state.settings.ftpDestinations[i].allowInsecureTLS) HStack { Button("Verbindung testen") { test(state.settings.ftpDestinations[i]) }.disabled(testing) if testing { ProgressView().controlSize(.small) } Text(testResult).font(.caption).lineLimit(3) } } .lkForm() .onAppear { password = Keychain.get(state.settings.ftpDestinations[i].keychainAccount) ?? "" } .onChange(of: selected) { _, _ in testResult = "" if let i = index { password = Keychain.get(state.settings.ftpDestinations[i].keychainAccount) ?? "" } } } else { Text("Server hinzufügen oder auswählen").foregroundStyle(.secondary).frame(maxWidth: .infinity, maxHeight: .infinity) } } } private func test(_ d: FTPDestination) { testing = true testResult = "" Task { do { try await FTPUploader().testConnection(d, password: Keychain.get(d.keychainAccount)) testResult = "✅ Verbindung OK" } catch { testResult = "❌ " + error.localizedDescription } testing = false } } } struct ImmichSettingsView: View { @EnvironmentObject var state: AppState @State private var apiKey = "" @State private var result = "" var body: some View { Form { Toggle("Immich-Upload aktivieren", isOn: $state.settings.immich.enabled) TextField("Server-URL", text: $state.settings.immich.serverURL, prompt: Text("https://immich.example.de")) SecureField("API-Schlüssel (Schlüsselbund)", text: $apiKey) .onChange(of: apiKey) { _, k in Keychain.set(k, account: ImmichSettings.keychainAccount); state.uploads.resetImmich() } TextField("Album", text: $state.settings.immich.albumName, prompt: Text("{event}")) TextField("Album, wenn kein Ereignis im IPTC", text: $state.settings.immich.albumFallback, prompt: Text("{isodate} {city}")) Text("Variablen aus IPTC/EXIF pro Bild, z. B. {event}, {headline}, {city}, {sublocation}, {isodate}, {date}, {year4}, {creator}. Fehlende Alben werden angelegt, leer = kein Album.") .font(.caption).foregroundStyle(.secondary) if let first = state.selectedItems.first { LabeledContent("Beispiel (\(first.filename))", value: state.immichAlbum(for: first).isEmpty ? "– kein Album –" : state.immichAlbum(for: first)) .font(.caption) } Picker("Dateien", selection: $state.settings.immich.variant) { ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) } } HStack { Button("Verbindung testen") { test() } Text(result).font(.caption) } Text("API-Schlüssel in Immich: Konto-Einstellungen → API-Schlüssel. Benötigte Rechte: asset.upload, album.read, album.create, albumAsset.create.") .font(.caption).foregroundStyle(.secondary) } .lkForm() .onAppear { apiKey = Keychain.get(ImmichSettings.keychainAccount) ?? "" } .onChange(of: state.settings.immich) { _, _ in state.uploads.resetImmich() } } private func test() { result = "…" Task { do { let c = try ImmichClient(settings: state.settings.immich, apiKey: apiKey) result = "✅ Angemeldet als \(try await c.testConnection())" } catch { result = "❌ " + error.localizedDescription } } } } struct LightroomSettingsView: View { @EnvironmentObject var state: AppState @State private var pluginMessage = "" var body: some View { Form { Section("Lichtkasten-Bridge-Plugin") { HStack { if LightroomBridge.pluginIsAlive { Label("Plugin aktiv (Lightroom läuft)", systemImage: "checkmark.circle.fill").foregroundStyle(.green) } else if LightroomBridge.pluginInstalled { Label("Installiert – Lightroom starten", systemImage: "pause.circle").foregroundStyle(.orange) } else { Label("Nicht installiert", systemImage: "xmark.circle").foregroundStyle(.red) } Spacer() Button(LightroomBridge.pluginInstalled ? "Neu installieren" : "Plugin installieren") { install() } } if !pluginMessage.isEmpty { Text(pluginMessage).font(.caption) } Text("Ohne Plugin öffnet ⌘⇧L den normalen Importdialog von Lightroom.") .font(.caption).foregroundStyle(.secondary) } Section("Import") { TextField("Entwicklungsvorgabe (exakter Name, optional „Ordner/Name“)", text: $state.settings.lightroom.developPreset) TextField("Sammlung (leer = keine)", text: $state.settings.lightroom.collection) } Section("Bearbeiten (⌘E)") { Toggle("Entwicklungsvorgabe auch bei ⌘E anwenden", isOn: $state.settings.lightroom.presetOnEdit) Text("⌘E importiert die Auswahl in den offenen Katalog und öffnet das Entwickeln-Modul.") .font(.caption).foregroundStyle(.secondary) } Section("JPEG-Export (⌘⌥L) → SENT") { Picker("Exportziel", selection: $state.settings.lightroom.exportTarget) { ForEach(ExportTarget.allCases, id: \.self) { Text($0.title).tag($0) } } TextField("Name des SENT-Ordners", text: $state.settings.lightroom.sentFolderName) if state.settings.lightroom.exportTarget == .fixed { HStack { TextField("Fester Exportordner", text: $state.settings.lightroom.exportFolder) Button("Wählen …") { let p = NSOpenPanel(); p.canChooseDirectories = true; p.canChooseFiles = false; p.canCreateDirectories = true if p.runModal() == .OK, let u = p.url { state.settings.lightroom.exportFolder = u.path } } } } Toggle("Nach dem Export den SENT-Ordner öffnen (zum Beschriften)", isOn: $state.settings.lightroom.openSentAfterExport) Stepper("JPEG-Qualität: \(state.settings.lightroom.jpegQuality)", value: $state.settings.lightroom.jpegQuality, in: 50...100, step: 5) TextField("Lange Kante in px (0 = volle Größe)", value: $state.settings.lightroom.longEdge, format: .number.grouping(.never)) Picker("Ausgabeschärfung", selection: $state.settings.lightroom.sharpening) { Text("Keine").tag("none"); Text("Bildschirm").tag("screen"); Text("Matt").tag("matte"); Text("Glanz").tag("glossy") } Picker("Farbraum", selection: $state.settings.lightroom.colorSpace) { Text("sRGB").tag("sRGB"); Text("Adobe RGB").tag("AdobeRGB") } Toggle("Original-IPTC nach Export erneut schreiben (PM-identischer Aufbau)", isOn: $state.settings.lightroom.rewriteIPTCAfterExport) } Section("Nach dem Export automatisch hochladen") { ForEach(state.settings.ftpDestinations) { d in Toggle("FTP: \(d.name)", isOn: uploadBinding(d.id.uuidString)) } Toggle("Immich", isOn: uploadBinding("immich")).disabled(!state.settings.immich.enabled) } } .lkForm() } private func uploadBinding(_ id: String) -> Binding { Binding(get: { state.settings.lightroom.autoUploadTargets.contains(id) }, set: { on in state.settings.lightroom.autoUploadTargets.removeAll { $0 == id } if on { state.settings.lightroom.autoUploadTargets.append(id) } }) } private func install() { guard let bundle = Bundle.main.url(forResource: "LichtkastenBridge", withExtension: "lrplugin") else { pluginMessage = "Plugin nicht im App-Bundle gefunden. Bitte LightroomPlugin/LichtkastenBridge.lrplugin über Lightroom → Zusatzmodul-Manager hinzufügen." return } do { try LightroomBridge.installPlugin(from: bundle) pluginMessage = "Installiert. Lightroom Classic bitte neu starten." } catch { pluginMessage = error.localizedDescription } } } struct CodesSettings: View { @EnvironmentObject var state: AppState var body: some View { Form { Section("Code-Ersetzung") { Text("\(state.codeLibrary.sets.filter(\.enabled).count) von \(state.codeLibrary.sets.count) Teams aktiv · \(state.codes.table.count) Codes") Button("Code-Ersetzungen öffnen … (⌘⇧K)") { state.openWindow("codes") } } } .lkForm() } }