Jellyfin: der Anmeldebildschirm bietet jetzt beides an
Der Anmeldebildschirm kannte nur Plex. JellyfinKit war fertig, aber von der App aus nicht erreichbar — „ich sehe nix von Jellyfin". Quick Connect steht vorn: der Server nennt einen sechsstelligen Code, den man in einem bereits angemeldeten Client bestätigt. Das Passwort erreicht Flixy dabei nie, dieselbe Zusage wie bei Plex. Benutzername und Passwort sind der Rückfall für Server, auf denen Quick Connect abgeschaltet ist; das Passwort wird dann für die Dauer einer Anfrage gehalten und danach weggeworfen. Die Adresse wird nicht erraten, sondern durchprobiert. „192.168.1.50" kann alles Mögliche heißen, und die Reihenfolge ist der Kern von JellyfinAddress: eine IP-Adresse im eigenen Netz spricht fast nie HTTPS, ein Domänenname fast immer. Andersherum wartet man bei jedem Server ohne Zertifikat erst auf eine Zeitüberschreitung. Die Sitzung hält von hier an einen Server hinter dem neutralen Vertrag, nicht mehr einen Plex-Server. Die Ansichten haben das nicht gemerkt — genau dafür war MediaKit da. Dabei fällt ab, was Jellyfin kann und Plex nicht: Favoriten stehen im Aktionsmenü, sobald der Server sie kennt, Sterne nur dort, wo es sie gibt. Was noch nicht geht und deshalb auch nicht behauptet wird: Wiedergabe und Live-TV sprechen weiter unmittelbar mit Plex. Bei Jellyfin verschwindet der Live-TV-Eintrag aus der Seitenleiste, und der Player sagt, dass die Wiedergabe der nächste Schritt ist, statt „Server nicht erreichbar" zu melden — er ist ja erreichbar. Nebenbei zwei Stellen, die der Übersetzer aus Plex hinterlassen hat: `catch is CancellationError` griff seit den getippten Fehlern nie mehr, weil eine abgebrochene Netzanfrage als Übertragungsfehler zurückkommt; und das Ersatz-Hintergrundbild einer Folge war toter Code, weil die linke Seite des `??` gar nicht optional war. TokenStore wandert nach MediaKit — Tokens sind nichts Plex-Eigenes. Die Konten sind nach Server getrennt, damit ein späteres Umschalten nicht jedes Mal eine neue Anmeldung kostet; „Abmelden" räumt trotzdem beide ab. 248 Tests grün. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9540f26dd8
commit
5696254034
@@ -1,13 +1,16 @@
|
||||
import SwiftUI
|
||||
import FlixyDesign
|
||||
import MediaKit
|
||||
import PlexKit
|
||||
|
||||
/// Das Aktionsmenü auf einer Detailseite.
|
||||
///
|
||||
/// Alles, was den Server verändert, liegt hier zusammen — statt verstreut als
|
||||
/// einzelne Knöpfe. Das hält die Kopfzeile frei für das, was man ständig
|
||||
/// braucht: Abspielen und Herunterladen.
|
||||
///
|
||||
/// Welche Einträge erscheinen, entscheidet der Server: Plex kennt Sterne, aber
|
||||
/// keine Favoriten, Jellyfin Favoriten, aber keine Sterne. Ein Eintrag, der
|
||||
/// nichts bewirkt, ist schlimmer als keiner.
|
||||
struct ItemActionsMenu: View {
|
||||
let item: MediaItem
|
||||
/// Wird gerufen, wenn sich am Server etwas geändert hat und die
|
||||
@@ -18,14 +21,18 @@ struct ItemActionsMenu: View {
|
||||
@State private var isWorking = false
|
||||
@State private var errorMessage: String?
|
||||
|
||||
private var capabilities: Set<BackendCapability> {
|
||||
session.backend?.capabilities ?? []
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Button {
|
||||
run { server in
|
||||
run { backend in
|
||||
if item.isWatched {
|
||||
try await server.markUnwatched(id: item.id)
|
||||
try await backend.markUnwatched(id: item.id)
|
||||
} else {
|
||||
try await server.markWatched(id: item.id)
|
||||
try await backend.markWatched(id: item.id)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
@@ -35,25 +42,38 @@ struct ItemActionsMenu: View {
|
||||
)
|
||||
}
|
||||
|
||||
Menu {
|
||||
ForEach((1...5).reversed(), id: \.self) { stars in
|
||||
Button {
|
||||
// Plex rechnet in Zehnteln: fünf Sterne sind eine 10.
|
||||
run { try await $0.rate(id: item.id, rating: stars * 2) }
|
||||
} label: {
|
||||
Label(String(repeating: "★", count: stars), systemImage: "star")
|
||||
}
|
||||
if capabilities.contains(.favourites) {
|
||||
Button {
|
||||
run { try await $0.setFavourite(!item.isFavourite, id: item.id) }
|
||||
} label: {
|
||||
Label(
|
||||
item.isFavourite ? "action.removeFavourite" : "action.addFavourite",
|
||||
systemImage: item.isFavourite ? "heart.slash" : "heart"
|
||||
)
|
||||
}
|
||||
if item.rating != nil {
|
||||
Divider()
|
||||
Button(role: .destructive) {
|
||||
run { try await $0.rate(id: item.id, rating: 0) }
|
||||
} label: {
|
||||
Label("action.clearRating", systemImage: "star.slash")
|
||||
}
|
||||
|
||||
if capabilities.contains(.ratings) {
|
||||
Menu {
|
||||
ForEach((1...5).reversed(), id: \.self) { stars in
|
||||
Button {
|
||||
// In Zehnteln: fünf Sterne sind eine 10.
|
||||
run { try await $0.rate(id: item.id, rating: stars * 2) }
|
||||
} label: {
|
||||
Label(String(repeating: "★", count: stars), systemImage: "star")
|
||||
}
|
||||
}
|
||||
if item.rating != nil {
|
||||
Divider()
|
||||
Button(role: .destructive) {
|
||||
run { try await $0.rate(id: item.id, rating: 0) }
|
||||
} label: {
|
||||
Label("action.clearRating", systemImage: "star.slash")
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label("action.rate", systemImage: "star")
|
||||
}
|
||||
} label: {
|
||||
Label("action.rate", systemImage: "star")
|
||||
}
|
||||
} label: {
|
||||
if isWorking {
|
||||
@@ -78,7 +98,7 @@ struct ItemActionsMenu: View {
|
||||
/// Bewusst ohne vorweggenommene Anzeige: den Haken sofort zu setzen und
|
||||
/// bei einem Fehler wieder zurückzunehmen sieht aus wie ein Wackler. Die
|
||||
/// Aktionen dauern Millisekunden.
|
||||
private func run(_ action: @escaping (PlexBackend) async throws -> Void) {
|
||||
private func run(_ action: @escaping (any MediaBackend) async throws -> Void) {
|
||||
guard let backend = session.backend else { return }
|
||||
isWorking = true
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ struct HomeView: View {
|
||||
.toolbarColorScheme(.dark, for: .navigationBar)
|
||||
.toolbar { SearchToolbarItem() }
|
||||
.navigationDestination(for: MediaRoute.self) { MediaDetailView(route: $0) }
|
||||
.task(id: session.server?.name) { await load() }
|
||||
.task(id: session.serverName) { await load() }
|
||||
.refreshable { await load() }
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ struct LibraryFilterSheet: View {
|
||||
|
||||
private func loadGenres() async {
|
||||
guard let server = session.backend,
|
||||
let library = session.mediaLibraries.first(where: { $0.kind == libraryKind })
|
||||
let library = session.libraries.first(where: { $0.kind == libraryKind })
|
||||
else { return }
|
||||
genres = (try? await server.filterOptions(inLibrary: library, field: .genre)) ?? []
|
||||
}
|
||||
|
||||
@@ -184,9 +184,10 @@ struct LibraryView: View {
|
||||
items = first.items
|
||||
page = first
|
||||
state = .loaded(())
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
// Siehe `LoadState.load`: eine abgebrochene Netzanfrage meldet
|
||||
// sich als Übertragungsfehler, nicht als Abbruch.
|
||||
if Task.isCancelled { return }
|
||||
state = .failed(message: ErrorText.describe(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +36,16 @@ extension LoadState {
|
||||
) async -> Self {
|
||||
do {
|
||||
return .loaded(try await operation())
|
||||
} catch is CancellationError {
|
||||
} catch {
|
||||
// Der Bildschirm wurde verlassen, während geladen wurde. Ein
|
||||
// Fehlertext wäre hier falsch — es ist niemand mehr da, den er
|
||||
// interessiert.
|
||||
return previous ?? .loading
|
||||
} catch {
|
||||
//
|
||||
// Gefragt wird die Aufgabe, nicht der Fehler: eine abgebrochene
|
||||
// Netzanfrage kommt als Übertragungsfehler zurück und nicht als
|
||||
// `CancellationError`. Danach zu fangen sah richtig aus und griff
|
||||
// nie.
|
||||
if Task.isCancelled { return previous ?? .loading }
|
||||
return .failed(message: ErrorText.describe(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,8 @@ struct RootView: View {
|
||||
diagnostics: diagnostics,
|
||||
policy: settings.policy(for: network),
|
||||
settings: settings,
|
||||
isLocalConnection: session.server?.connection.local ?? false
|
||||
isLocalConnection: session.server?.connection.local ?? false,
|
||||
unavailableMessage: session.playbackUnavailableMessage
|
||||
)
|
||||
// Aus Bild-in-Bild zurückzukehren soll im Vollbild landen, nicht in
|
||||
// der Kachel — dort kam man vorher gar nicht mehr heraus.
|
||||
@@ -146,7 +147,7 @@ struct RootView: View {
|
||||
}
|
||||
|
||||
private var sidebarDestinations: [SidebarDestination] {
|
||||
session.mediaLibraries.map { .library(key: $0.id, title: $0.title) }
|
||||
session.libraries.map { .library(key: $0.id, title: $0.title) }
|
||||
}
|
||||
|
||||
/// iPad: die Seitenleiste ist Teil des Fensters.
|
||||
@@ -154,6 +155,7 @@ struct RootView: View {
|
||||
NavigationSplitView {
|
||||
SidebarView(
|
||||
libraries: sidebarDestinations,
|
||||
showsLiveTV: session.supportsLiveTV,
|
||||
selection: $selection,
|
||||
showsHeader: false
|
||||
) {}
|
||||
@@ -167,7 +169,11 @@ struct RootView: View {
|
||||
/// iPhone: die Seitenleiste fährt über den Inhalt.
|
||||
private var drawerLayout: some View {
|
||||
DrawerContainer(isOpen: $isSidebarOpen) {
|
||||
SidebarView(libraries: sidebarDestinations, selection: $selection) {
|
||||
SidebarView(
|
||||
libraries: sidebarDestinations,
|
||||
showsLiveTV: session.supportsLiveTV,
|
||||
selection: $selection
|
||||
) {
|
||||
isSidebarOpen = false
|
||||
}
|
||||
} content: {
|
||||
@@ -196,7 +202,7 @@ struct RootView: View {
|
||||
case .home:
|
||||
HomeView()
|
||||
case .library(let key, let title):
|
||||
if let library = session.mediaLibraries.first(where: { $0.id == key }) {
|
||||
if let library = session.libraries.first(where: { $0.id == key }) {
|
||||
LibraryView(library: library)
|
||||
} else {
|
||||
PlaceholderScreen(destination: .library(key: key, title: title))
|
||||
|
||||
@@ -8,6 +8,12 @@ import FlixyDesign
|
||||
/// `NavigationSplitView` stecken, ohne etwas zu ändern.
|
||||
struct SidebarView: View {
|
||||
let libraries: [SidebarDestination]
|
||||
/// Ob der aktive Server Live-TV anbietet.
|
||||
///
|
||||
/// Ein Eintrag, der zu einem leeren Bildschirm führt, ist schlimmer als
|
||||
/// keiner — und bei Jellyfin führt er dorthin, bis der Programmführer
|
||||
/// umgestellt ist.
|
||||
var showsLiveTV: Bool = true
|
||||
@Binding var selection: SidebarDestination
|
||||
/// Auf dem iPad trägt die Navigationsleiste den Namen bereits — dort wäre
|
||||
/// eine eigene Überschrift die dritte Nennung auf demselben Bildschirm.
|
||||
@@ -27,7 +33,7 @@ struct SidebarView: View {
|
||||
|
||||
section(
|
||||
title: String(localized: "sidebar.more"),
|
||||
items: [.liveTV, .downloads, .settings]
|
||||
items: showsLiveTV ? [.liveTV, .downloads, .settings] : [.downloads, .settings]
|
||||
)
|
||||
}
|
||||
.padding(.horizontal, FlixySpacing.regular)
|
||||
|
||||
@@ -99,6 +99,13 @@ final class PlayerModel {
|
||||
private let policy: PlaybackPolicy
|
||||
private let settings: PlaybackSettings
|
||||
private let isLocalConnection: Bool
|
||||
/// Was zu sagen ist, wenn es keinen Server gibt, mit dem sich abspielen
|
||||
/// ließe.
|
||||
///
|
||||
/// Als Text durchgereicht statt hier entschieden: bei Plex heißt das
|
||||
/// „nicht erreichbar", bei Jellyfin „kommt als Nächstes", und welcher
|
||||
/// Server angemeldet ist, weiß die Sitzung, nicht der Player.
|
||||
private let unavailableMessage: String
|
||||
|
||||
private var item: PlexItem?
|
||||
/// Die gerade gespielte Fassung und Datei.
|
||||
@@ -127,7 +134,8 @@ final class PlayerModel {
|
||||
diagnostics: PlaybackDiagnostics,
|
||||
policy: PlaybackPolicy,
|
||||
settings: PlaybackSettings,
|
||||
isLocalConnection: Bool
|
||||
isLocalConnection: Bool,
|
||||
unavailableMessage: String
|
||||
) {
|
||||
self.request = request
|
||||
self.server = server
|
||||
@@ -136,6 +144,7 @@ final class PlayerModel {
|
||||
self.policy = policy
|
||||
self.settings = settings
|
||||
self.isLocalConnection = isLocalConnection
|
||||
self.unavailableMessage = unavailableMessage
|
||||
self.title = request.title
|
||||
}
|
||||
|
||||
@@ -158,7 +167,7 @@ final class PlayerModel {
|
||||
}
|
||||
|
||||
guard let server else {
|
||||
phase = .failed(message: String(localized: "error.serverUnreachable"))
|
||||
phase = .failed(message: unavailableMessage)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -113,9 +113,13 @@ struct SearchView: View {
|
||||
do {
|
||||
hubs = try await backend.search(trimmed, limit: 30)
|
||||
if !hubs.isEmpty { remember(trimmed) }
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
// Abgebrochen, weil weitergetippt oder der Bildschirm verlassen
|
||||
// wurde: `Task.isCancelled` statt `catch is CancellationError` —
|
||||
// eine abgebrochene Netzanfrage kommt als Übertragungsfehler
|
||||
// zurück, nicht als Abbruch, und die alte Prüfung lief deshalb
|
||||
// ins Leere.
|
||||
if Task.isCancelled { return }
|
||||
hubs = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import SwiftUI
|
||||
import FlixyDesign
|
||||
import FlixyDownloads
|
||||
import FlixyPlayback
|
||||
import MediaKit
|
||||
import PlexKit
|
||||
|
||||
/// Die Einstellungen.
|
||||
@@ -18,18 +19,29 @@ struct SettingsView: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
if let server = session.server {
|
||||
if session.backend != nil {
|
||||
Section("settings.server") {
|
||||
LabeledContent("settings.serverName", value: server.name)
|
||||
LabeledContent("settings.connection", value: connectionLabel(server.connection))
|
||||
LabeledContent("settings.address", value: server.connection.uri)
|
||||
.font(.flixyCaption)
|
||||
.textSelection(.enabled)
|
||||
LabeledContent("settings.serverName", value: session.serverName)
|
||||
// Welche Art von Server — bei zwei möglichen ist das keine
|
||||
// Nebensache mehr, sondern die erste Frage bei jeder
|
||||
// Rückmeldung.
|
||||
LabeledContent("settings.serverKind", value: kindLabel)
|
||||
if let connection = session.server?.connection {
|
||||
LabeledContent("settings.connection", value: connectionLabel(connection))
|
||||
}
|
||||
if let address = session.serverAddress {
|
||||
LabeledContent("settings.address", value: address)
|
||||
.font(.flixyCaption)
|
||||
.textSelection(.enabled)
|
||||
}
|
||||
if let accountName = session.accountName {
|
||||
LabeledContent("settings.account", value: accountName)
|
||||
}
|
||||
}
|
||||
|
||||
Section("settings.libraries") {
|
||||
ForEach(session.libraries) { library in
|
||||
LabeledContent(library.title, value: library.type.capitalized)
|
||||
LabeledContent(library.title, value: library.kind.label)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,6 +188,15 @@ struct SettingsView: View {
|
||||
|
||||
/// Zeigt, über welchen Weg die Verbindung läuft — beim Suchen nach
|
||||
/// Ruckeln ist das die erste Frage.
|
||||
/// Welche Serverart gerade bedient wird.
|
||||
private var kindLabel: String {
|
||||
switch session.kind {
|
||||
case .plex: "Plex"
|
||||
case .jellyfin: "Jellyfin"
|
||||
case nil: "—"
|
||||
}
|
||||
}
|
||||
|
||||
private func connectionLabel(_ connection: PlexConnection) -> String {
|
||||
if connection.local { return String(localized: "settings.connectionLocal") }
|
||||
if connection.relay { return String(localized: "settings.connectionRelay") }
|
||||
@@ -194,3 +215,21 @@ extension PlaybackSettings.Quality {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MediaLibrary.Kind {
|
||||
/// Wie diese Art von Mediathek heißt.
|
||||
///
|
||||
/// Übersetzt statt durchgereicht: die Server liefern „movies" und
|
||||
/// „tvshows", und das großgeschrieben anzuzeigen war eine englische
|
||||
/// Beschriftung in einer deutschen Oberfläche.
|
||||
var label: String {
|
||||
switch self {
|
||||
case .movie: String(localized: "library.kind.movie")
|
||||
case .show: String(localized: "library.kind.show")
|
||||
case .music: String(localized: "library.kind.music")
|
||||
case .photo: String(localized: "library.kind.photo")
|
||||
case .liveTV: String(localized: "library.kind.liveTV")
|
||||
case .other: String(localized: "library.kind.other")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
import SwiftUI
|
||||
import FlixyDesign
|
||||
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(FlixySession.self) private var session
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.flixyAccent) 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, FlixySpacing.section)
|
||||
.padding(.vertical, FlixySpacing.section)
|
||||
.frame(maxWidth: 420)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
.background(Color.flixyCanvas)
|
||||
.navigationTitle(Text("signIn.jellyfin.title"))
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.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 Blatt 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: FlixySpacing.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(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyDestructive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Adresse
|
||||
|
||||
@ViewBuilder
|
||||
private func addressStep(model: JellyfinSignInModel) -> some View {
|
||||
@Bindable var model = model
|
||||
|
||||
VStack(alignment: .leading, spacing: FlixySpacing.regular) {
|
||||
Text("signIn.jellyfin.addressPrompt")
|
||||
.font(.flixyRowHeader)
|
||||
.foregroundStyle(Color.flixyTextPrimary)
|
||||
|
||||
TextField("signIn.jellyfin.addressPlaceholder", text: $model.address)
|
||||
.textFieldStyle(.plain)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.URL)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
.submitLabel(.go)
|
||||
.focused($focusedField, equals: .address)
|
||||
.onSubmit { Task { await model.findServer() } }
|
||||
// Hier statt beim Öffnen des Blattes: so bekommt das Feld den
|
||||
// Fokus auch dann, wenn man nach einem Vertipper zurückkommt.
|
||||
.task { focusedField = .address }
|
||||
.padding(FlixySpacing.regular)
|
||||
.background(Color.flixyElevated, in: .rect(cornerRadius: FlixyRadius.control))
|
||||
.foregroundStyle(Color.flixyTextPrimary)
|
||||
|
||||
// Ein Beispiel statt einer Erklärung: „Schema, Host, Port" sagt
|
||||
// niemandem etwas, „192.168.1.50" jedem.
|
||||
Text("signIn.jellyfin.addressHint")
|
||||
.font(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextMuted)
|
||||
|
||||
Button {
|
||||
focusedField = nil
|
||||
Task { await model.findServer() }
|
||||
} label: {
|
||||
Text("signIn.jellyfin.connect")
|
||||
.font(.flixyRowHeader)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, FlixySpacing.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: FlixySpacing.regular) {
|
||||
foundServerHeader(model: model)
|
||||
|
||||
Text("signIn.jellyfin.quickConnectHint")
|
||||
.font(.flixyBody)
|
||||
.foregroundStyle(Color.flixyTextSecondary)
|
||||
|
||||
Text(code)
|
||||
.font(.system(.largeTitle, design: .monospaced, weight: .semibold))
|
||||
.tracking(8)
|
||||
.foregroundStyle(Color.flixyTextPrimary)
|
||||
.textSelection(.enabled)
|
||||
.padding(.vertical, FlixySpacing.regular)
|
||||
.frame(maxWidth: .infinity)
|
||||
.background(Color.flixyElevated, in: .rect(cornerRadius: FlixyRadius.control))
|
||||
|
||||
HStack(spacing: FlixySpacing.snug) {
|
||||
ProgressView().controlSize(.small)
|
||||
Text("signIn.jellyfin.waitingForApproval")
|
||||
.font(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextMuted)
|
||||
}
|
||||
|
||||
Text("signIn.jellyfin.privacy")
|
||||
.font(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextMuted)
|
||||
|
||||
Divider().overlay(Color.flixySeparator)
|
||||
|
||||
Button("signIn.jellyfin.usePassword") { model.useCredentials() }
|
||||
.font(.flixyCaption)
|
||||
Button("signIn.jellyfin.otherAddress") { model.startOver() }
|
||||
.font(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextSecondary)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Benutzername und Passwort
|
||||
|
||||
@ViewBuilder
|
||||
private func credentialsStep(model: JellyfinSignInModel) -> some View {
|
||||
@Bindable var model = model
|
||||
|
||||
VStack(alignment: .leading, spacing: FlixySpacing.regular) {
|
||||
foundServerHeader(model: model)
|
||||
|
||||
TextField("signIn.jellyfin.userName", text: $model.userName)
|
||||
.textContentType(.username)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
.submitLabel(.next)
|
||||
.focused($focusedField, equals: .userName)
|
||||
.onSubmit { focusedField = .password }
|
||||
.padding(FlixySpacing.regular)
|
||||
.background(Color.flixyElevated, in: .rect(cornerRadius: FlixyRadius.control))
|
||||
|
||||
SecureField("signIn.jellyfin.password", text: $model.password)
|
||||
.textContentType(.password)
|
||||
.submitLabel(.go)
|
||||
.focused($focusedField, equals: .password)
|
||||
.onSubmit { Task { await model.signInWithPassword() } }
|
||||
.padding(FlixySpacing.regular)
|
||||
.background(Color.flixyElevated, in: .rect(cornerRadius: FlixyRadius.control))
|
||||
|
||||
Button {
|
||||
focusedField = nil
|
||||
Task { await model.signInWithPassword() }
|
||||
} label: {
|
||||
Text("signIn.jellyfin.submit")
|
||||
.font(.flixyRowHeader)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, FlixySpacing.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(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextMuted)
|
||||
|
||||
Divider().overlay(Color.flixySeparator)
|
||||
|
||||
if model.offersQuickConnect {
|
||||
Button("signIn.jellyfin.useCode") { Task { await model.beginQuickConnect() } }
|
||||
.font(.flixyCaption)
|
||||
}
|
||||
Button("signIn.jellyfin.otherAddress") { model.startOver() }
|
||||
.font(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextSecondary)
|
||||
}
|
||||
.foregroundStyle(Color.flixyTextPrimary)
|
||||
}
|
||||
|
||||
// MARK: - Bausteine
|
||||
|
||||
@ViewBuilder
|
||||
private func foundServerHeader(model: JellyfinSignInModel) -> some View {
|
||||
VStack(alignment: .leading, spacing: FlixySpacing.tight) {
|
||||
Text("signIn.jellyfin.foundServer")
|
||||
.font(.flixyCaption)
|
||||
.foregroundStyle(Color.flixyTextMuted)
|
||||
.textCase(.uppercase)
|
||||
Text(model.serverName ?? model.address)
|
||||
.font(.flixyTitle)
|
||||
.foregroundStyle(Color.flixyTextPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func waiting(text: LocalizedStringKey) -> some View {
|
||||
HStack(spacing: FlixySpacing.snug) {
|
||||
ProgressView().controlSize(.small)
|
||||
Text(text)
|
||||
.font(.flixyBody)
|
||||
.foregroundStyle(Color.flixyTextSecondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.vertical, FlixySpacing.section)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,26 @@
|
||||
import SwiftUI
|
||||
import FlixyDesign
|
||||
import PlexKit
|
||||
|
||||
/// Der Anmeldebildschirm.
|
||||
///
|
||||
/// Ein Knopf, mehr nicht. Die Anmeldemaske kommt von Plex und öffnet sich in
|
||||
/// einem Fenster innerhalb der App; das Passwort wird dort eingegeben und
|
||||
/// erreicht Flixy nie. Nach dem Anmelden schließt sich das Fenster von selbst.
|
||||
/// Zwei Wege, weil es zwei Serverarten gibt. **Plex** öffnet seine eigene
|
||||
/// Anmeldemaske in einem Fenster innerhalb der App; das Passwort wird dort
|
||||
/// eingegeben und erreicht Flixy nie. **Jellyfin** hat kein Verzeichnis wie
|
||||
/// plex.tv — dort wird die Adresse des eigenen Servers eingetippt und, wann
|
||||
/// immer der Server es anbietet, ein Code bestätigt statt eines Passworts.
|
||||
///
|
||||
/// Die beiden Wege sind absichtlich nicht zu einem zusammengefasst. Sie haben
|
||||
/// nichts gemeinsam außer dem Ziel, und der Versuch, das zu verstecken, würde
|
||||
/// beide verschlechtern.
|
||||
struct SignInView: View {
|
||||
let phase: FlixySession.Phase
|
||||
/// Der Code der laufenden Anmeldung, sobald er gezeigt werden soll.
|
||||
/// Der Code der laufenden Plex-Anmeldung, sobald er gezeigt werden soll.
|
||||
let manualCode: String?
|
||||
let onSignIn: () -> Void
|
||||
let onCancel: () -> Void
|
||||
|
||||
@Environment(\.flixyAccent) private var accent
|
||||
@State private var showsJellyfinSignIn = false
|
||||
|
||||
private var isAuthenticating: Bool {
|
||||
if case .authenticating = phase { return true }
|
||||
@@ -48,7 +54,7 @@ struct SignInView: View {
|
||||
if isAuthenticating {
|
||||
ProgressView().tint(Color.flixyCanvas)
|
||||
} else {
|
||||
Text("signIn.action").font(.flixyRowHeader)
|
||||
Text("signIn.withPlex").font(.flixyRowHeader)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
@@ -58,6 +64,18 @@ struct SignInView: View {
|
||||
.tint(accent)
|
||||
.disabled(isAuthenticating)
|
||||
|
||||
Button {
|
||||
showsJellyfinSignIn = true
|
||||
} label: {
|
||||
Text("signIn.withJellyfin")
|
||||
.font(.flixyRowHeader)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, FlixySpacing.regular)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(Color.flixyTextSecondary)
|
||||
.disabled(isAuthenticating)
|
||||
|
||||
if let manualCode {
|
||||
manualFallback(code: manualCode)
|
||||
} else {
|
||||
@@ -74,6 +92,9 @@ struct SignInView: View {
|
||||
.frame(maxWidth: 420)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color.flixyCanvas)
|
||||
.sheet(isPresented: $showsJellyfinSignIn) {
|
||||
JellyfinSignInView()
|
||||
}
|
||||
}
|
||||
|
||||
/// Der Ausweg, wenn die Browser-Seite den Code nicht verknüpft.
|
||||
|
||||
Reference in New Issue
Block a user