luminate/Sources/Luminate/ClientSessionBinder.swift

48 lines
1.7 KiB
Swift

//
// ClientSessionBinder.swift
//
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
import LuminateServices
import LuminateUI
import Portico
/// Keeps the live Jellyfin client in step with session preference changes.
@MainActor package final class ClientSessionBinder {
private var tokens: [SubscriptionToken] = []
/// Subscribes to the server URL and access token preferences.
///
/// - Parameters:
/// - client: The client to reconfigure.
/// - preferences: The coordinator owning the preference slots.
package init(client: JellyfinClient, preferences: Preferences = .shared) {
tokens.append(
preferences.binding(for: .serverURL).subscribe { url in
guard let url else { return }
Task { await client.setServerURL(url) }
}
)
tokens.append(
preferences.binding(for: .accessToken).subscribe { token in
Task { await client.setAccessToken(token) }
}
)
}
}