Files
Flaro/Halo/Views/SignIn/JellyfinSignInView.swift
T
ScarriffleandClaude Opus 5 4b9a1e7b67 Flixy heißt ab hier Halo
Reine Umbenennung, kein Verhalten geändert — bewusst als eigener Commit,
damit „umbenannt" und „umgebaut" im Nachhinein auseinanderzuhalten sind.

712 mal `Flixy`, 778 mal `flixy`, 7 mal `FLIXY` in 169 Dateien, dazu 25
Pfade. Ziele: `Halo`, `HaloTV`, `HaloTopShelf`, `HaloUITests`, `HaloKit` mit
`HaloDesign`, `HaloDownloads`, `HaloPlayback` und `HaloProbe`. `MediaKit`,
`JellyfinKit` und `DownloadWidget` tragen den Namen nicht und bleiben.

`docs/superpowers/specs/` ist ausgenommen. Datierte Entwurfsdokumente sind
ein Protokoll getroffener Entscheidungen; sie nachträglich umzuschreiben
hiesse, die Vergangenheit zu glätten.

**Die Bundle-ID wandert mit** — ausdrücklich so gewollt, mit bekanntem Preis:
`com.scarriffleservices.halo` ist für iOS eine *andere* App. Die installierte
Fassung bleibt daneben stehen, mit Downloads und Anmeldung in ihrem Container;
Halo startet leer. Einmal neu anmelden, heruntergeladene Folgen einmal neu
laden. Dasselbe gilt für die App-Gruppe, die sich TV-App und Top Shelf teilen.

**Eine Folge davon, die beim Entscheiden noch nicht auf dem Tisch lag:** der
Aufräumschritt aus dem vorigen Commit kommt an die alten Plex-Token nicht mehr
heran. Der Schlüsselbund grenzt nach Team und Bundle-Kennung ab — was unter
`…flixy` liegt, ist für `…halo` unerreichbar. Erledigt wird es trotzdem, nur
anders: **die alte App löschen.** iOS räumt deren Schlüsselbund-Einträge beim
Deinstallieren mit ab. Der Code bleibt stehen, weil er für jeden Stand vor
dieser Umbenennung richtig ist und im Jahr einen Startvergleich kostet.

Die Projektdatei ist aus `project.yml` neu erzeugt, der alte Ordner gelöscht
statt umbenannt — sie steht ohnehin nicht im Repo.

Das Verzeichnis des Repos selbst heißt weiter `Flixy`; das umzubenennen ist
ein Handgriff ausserhalb des Projekts.

368 Tests grün. iOS und tvOS bauen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-03 11:12:32 +02:00

280 lines
11 KiB
Swift

import SwiftUI
import HaloDesign
import JellyfinKit
/// Die Anmeldung an einem Jellyfin-Server.
///
/// Drei Bildschirme in einem, weil es drei Fragen sind und nicht mehr: wo
/// steht der Server, wie heißt du, und — wenn der Server es kann — bestätige
/// diesen Code. Der Weg über den Code steht vorn, weil dabei kein Passwort
/// durch diese App läuft.
struct JellyfinSignInView: View {
@Environment(HaloSession.self) private var session
@Environment(\.dismiss) private var dismiss
@Environment(\.haloAccent) private var accent
@State private var model: JellyfinSignInModel?
@FocusState private var focusedField: Field?
private enum Field { case address, userName, password }
var body: some View {
NavigationStack {
ScrollView {
if let model {
content(for: model)
.padding(.horizontal, HaloSpacing.section)
.padding(.vertical, HaloSpacing.section)
.frame(maxWidth: 420)
.frame(maxWidth: .infinity)
}
}
.scrollDismissesKeyboard(.interactively)
.background(Color.haloCanvas)
.navigationTitle(Text("signIn.jellyfin.title"))
.haloInlineTitle()
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("action.cancel") {
model?.cancel()
dismiss()
}
}
}
}
.tint(accent)
.task {
// Erst hier, nicht im Eigenschaftswert: das Modell braucht die
// Gerätekennung der Sitzung. Baut es sich eine eigene, steht die
// App nach dem Anmelden ein zweites Mal in der Geräteliste.
guard model == nil else { return }
let fresh = JellyfinSignInModel(identity: session.jellyfinDeviceIdentity)
fresh.onAuthenticated = { client, account, serverName in
dismiss()
Task { await session.adoptJellyfin(client: client, account: account, serverName: serverName) }
}
model = fresh
}
.onDisappear {
// Wird das Sheet weggewischt, läuft sonst die Abfrageschleife
// noch minutenlang weiter — unsichtbar und für nichts.
model?.cancel()
}
}
@ViewBuilder
private func content(for model: JellyfinSignInModel) -> some View {
@Bindable var model = model
VStack(alignment: .leading, spacing: HaloSpacing.section) {
switch model.step {
case .address:
addressStep(model: model)
case .checking:
waiting(text: "signIn.jellyfin.searching")
case .quickConnect(let code):
quickConnectStep(model: model, code: code)
case .credentials:
credentialsStep(model: model)
case .signingIn:
waiting(text: "signIn.jellyfin.signingIn")
}
if let message = model.errorMessage {
Label(message, systemImage: "exclamationmark.triangle")
.font(.haloCaption)
.foregroundStyle(Color.haloDestructive)
}
}
}
// MARK: - Adresse
@ViewBuilder
private func addressStep(model: JellyfinSignInModel) -> some View {
@Bindable var model = model
VStack(alignment: .leading, spacing: HaloSpacing.regular) {
Text("signIn.jellyfin.addressPrompt")
.font(.haloRowHeader)
.foregroundStyle(Color.haloTextPrimary)
TextField("signIn.jellyfin.addressPlaceholder", text: $model.address)
.textFieldStyle(.plain)
.textContentType(.URL)
.haloPlainEntry(isAddress: true)
.submitLabel(.go)
.focused($focusedField, equals: .address)
.onSubmit { Task { await model.findServer() } }
// Hier statt beim Öffnen des Sheets: so bekommt das Feld den
// Fokus auch dann, wenn man nach einem Vertipper zurückkommt.
.task { focusedField = .address }
.padding(HaloSpacing.regular)
.background(Color.haloElevated, in: .rect(cornerRadius: HaloRadius.control))
.foregroundStyle(Color.haloTextPrimary)
// Ein Beispiel statt einer Erklärung: „Schema, Host, Port" sagt
// niemandem etwas, „192.168.1.50" jedem.
Text("signIn.jellyfin.addressHint")
.font(.haloCaption)
.foregroundStyle(Color.haloTextMuted)
Button {
focusedField = nil
Task { await model.findServer() }
} label: {
Text("signIn.jellyfin.connect")
.font(.haloRowHeader)
.frame(maxWidth: .infinity)
.padding(.vertical, HaloSpacing.regular)
}
.buttonStyle(.borderedProminent)
.tint(accent)
.disabled(model.address.trimmingCharacters(in: .whitespaces).isEmpty)
}
}
// MARK: - Code
@ViewBuilder
private func quickConnectStep(model: JellyfinSignInModel, code: String) -> some View {
VStack(alignment: .leading, spacing: HaloSpacing.regular) {
foundServerHeader(model: model)
Text("signIn.jellyfin.quickConnectHint")
.font(.haloBody)
.foregroundStyle(Color.haloTextSecondary)
Text(code)
.font(.system(.largeTitle, design: .monospaced, weight: .semibold))
.tracking(8)
.foregroundStyle(Color.haloTextPrimary)
.textSelection(.enabled)
.padding(.vertical, HaloSpacing.regular)
.frame(maxWidth: .infinity)
.background(Color.haloElevated, in: .rect(cornerRadius: HaloRadius.control))
HStack(spacing: HaloSpacing.snug) {
ProgressView().controlSize(.small)
Text("signIn.jellyfin.waitingForApproval")
.font(.haloCaption)
.foregroundStyle(Color.haloTextMuted)
}
Text("signIn.jellyfin.privacy")
.font(.haloCaption)
.foregroundStyle(Color.haloTextMuted)
Divider().overlay(Color.haloSeparator)
Button("signIn.jellyfin.usePassword") { model.useCredentials() }
.font(.haloCaption)
Button("signIn.jellyfin.otherAddress") { model.startOver() }
.font(.haloCaption)
.foregroundStyle(Color.haloTextSecondary)
}
}
// MARK: - Benutzername und Passwort
@ViewBuilder
private func credentialsStep(model: JellyfinSignInModel) -> some View {
@Bindable var model = model
VStack(alignment: .leading, spacing: HaloSpacing.regular) {
foundServerHeader(model: model)
TextField("signIn.jellyfin.userName", text: $model.userName)
.textContentType(.username)
.haloPlainEntry()
.submitLabel(.next)
.focused($focusedField, equals: .userName)
.onSubmit { focusedField = .password }
// **Tabulator weiterreichen, von Hand.**
//
// Auf dem Mac ist „Name, Tab, Passwort, Eingabe" der Weg, den
// jeder nimmt, der einen Passwortspeicher benutzt. SwiftUI
// schiebt den Fokus hier aber nicht selbst weiter: die Taste
// kommt im Feld an und bleibt dort liegen.
.onKeyPress(.tab) {
focusedField = .password
return .handled
}
.padding(HaloSpacing.regular)
.background(Color.haloElevated, in: .rect(cornerRadius: HaloRadius.control))
SecureField("signIn.jellyfin.password", text: $model.password)
.textContentType(.password)
.submitLabel(.go)
.focused($focusedField, equals: .password)
.onSubmit { Task { await model.signInWithPassword() } }
// Und zurück: sonst wäre der Weg eine Einbahnstraße, und ein
// Vertipper im Namen hieße, zur Maus greifen.
.onKeyPress(.tab) {
focusedField = .userName
return .handled
}
.padding(HaloSpacing.regular)
.background(Color.haloElevated, in: .rect(cornerRadius: HaloRadius.control))
Button {
focusedField = nil
Task { await model.signInWithPassword() }
} label: {
Text("signIn.jellyfin.submit")
.font(.haloRowHeader)
.frame(maxWidth: .infinity)
.padding(.vertical, HaloSpacing.regular)
}
.buttonStyle(.borderedProminent)
.tint(accent)
.disabled(model.userName.isEmpty)
// Das Passwort wird für die eine Anfrage gehalten und danach
// verworfen. Gespeichert wird nur der Token, und der im
// Schlüsselbund.
Text("signIn.jellyfin.passwordNote")
.font(.haloCaption)
.foregroundStyle(Color.haloTextMuted)
Divider().overlay(Color.haloSeparator)
if model.offersQuickConnect {
Button("signIn.jellyfin.useCode") { Task { await model.beginQuickConnect() } }
.font(.haloCaption)
}
Button("signIn.jellyfin.otherAddress") { model.startOver() }
.font(.haloCaption)
.foregroundStyle(Color.haloTextSecondary)
}
.foregroundStyle(Color.haloTextPrimary)
}
// MARK: - Bausteine
@ViewBuilder
private func foundServerHeader(model: JellyfinSignInModel) -> some View {
VStack(alignment: .leading, spacing: HaloSpacing.tight) {
Text("signIn.jellyfin.foundServer")
.font(.haloCaption)
.foregroundStyle(Color.haloTextMuted)
.textCase(.uppercase)
Text(model.serverName ?? model.address)
.font(.haloTitle)
.foregroundStyle(Color.haloTextPrimary)
}
}
@ViewBuilder
private func waiting(text: LocalizedStringKey) -> some View {
HStack(spacing: HaloSpacing.snug) {
ProgressView().controlSize(.small)
Text(text)
.font(.haloBody)
.foregroundStyle(Color.haloTextSecondary)
}
.frame(maxWidth: .infinity, alignment: .center)
.padding(.vertical, HaloSpacing.section)
}
}