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>
This commit is contained in:
co-authored by
Claude Opus 5
parent
2fcf6821c8
commit
4b9a1e7b67
@@ -0,0 +1,104 @@
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
/// Legt Tokens im Schlüsselbund ab.
|
||||
///
|
||||
/// Nicht in `UserDefaults`: ein Server-Token gibt vollen Zugriff auf die
|
||||
/// Mediathek und bleibt gültig, bis er am Server zurückgezogen wird. In den
|
||||
/// Voreinstellungen läge er als Klartext in einer Datei, die jedes Backup
|
||||
/// mitnimmt.
|
||||
///
|
||||
/// Der Kontoname trennt die Server: `plex.server` und `jellyfin.server`
|
||||
/// liegen nebeneinander. Wer zwischen beiden wechselt, soll beim
|
||||
/// Zurückwechseln nicht neu anmelden müssen.
|
||||
public protocol TokenStoring: Sendable {
|
||||
func store(_ token: String, for account: String) throws
|
||||
func token(for account: String) -> String?
|
||||
func remove(for account: String)
|
||||
}
|
||||
|
||||
public struct KeychainTokenStore: TokenStoring {
|
||||
private let service: String
|
||||
|
||||
public init(service: String) {
|
||||
self.service = service
|
||||
}
|
||||
|
||||
public enum Failure: Error, Equatable {
|
||||
case keychain(status: OSStatus)
|
||||
}
|
||||
|
||||
public func store(_ token: String, for account: String) throws {
|
||||
let query: [String: Any] = [
|
||||
kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrService as String: service,
|
||||
kSecAttrAccount as String: account,
|
||||
]
|
||||
|
||||
let attributes: [String: Any] = [
|
||||
kSecValueData as String: Data(token.utf8),
|
||||
// Ohne Gerätesperre kein Zugriff, und nicht in Backups übertragbar.
|
||||
// Ein Token, der auf einem anderen Gerät wieder auftaucht, wäre
|
||||
// ein stiller Zweitzugang zur Mediathek.
|
||||
kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
||||
]
|
||||
|
||||
let status = SecItemUpdate(query as CFDictionary, attributes as CFDictionary)
|
||||
switch status {
|
||||
case errSecSuccess:
|
||||
return
|
||||
case errSecItemNotFound:
|
||||
let insert = query.merging(attributes) { current, _ in current }
|
||||
let addStatus = SecItemAdd(insert as CFDictionary, nil)
|
||||
guard addStatus == errSecSuccess else { throw Failure.keychain(status: addStatus) }
|
||||
default:
|
||||
throw Failure.keychain(status: status)
|
||||
}
|
||||
}
|
||||
|
||||
public func token(for account: String) -> String? {
|
||||
let query: [String: Any] = [
|
||||
kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrService as String: service,
|
||||
kSecAttrAccount as String: account,
|
||||
kSecReturnData as String: true,
|
||||
kSecMatchLimit as String: kSecMatchLimitOne,
|
||||
]
|
||||
|
||||
var result: CFTypeRef?
|
||||
guard SecItemCopyMatching(query as CFDictionary, &result) == errSecSuccess,
|
||||
let data = result as? Data
|
||||
else { return nil }
|
||||
|
||||
return String(data: data, encoding: .utf8)
|
||||
}
|
||||
|
||||
public func remove(for account: String) {
|
||||
let query: [String: Any] = [
|
||||
kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrService as String: service,
|
||||
kSecAttrAccount as String: account,
|
||||
]
|
||||
SecItemDelete(query as CFDictionary)
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Ablageort im Arbeitsspeicher — für Tests und SwiftUI-Vorschauen.
|
||||
public final class InMemoryTokenStore: TokenStoring, @unchecked Sendable {
|
||||
private let lock = NSLock()
|
||||
private var tokens: [String: String] = [:]
|
||||
|
||||
public init() {}
|
||||
|
||||
public func store(_ token: String, for account: String) throws {
|
||||
lock.withLock { tokens[account] = token }
|
||||
}
|
||||
|
||||
public func token(for account: String) -> String? {
|
||||
lock.withLock { tokens[account] }
|
||||
}
|
||||
|
||||
public func remove(for account: String) {
|
||||
_ = lock.withLock { tokens.removeValue(forKey: account) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user