fix(offline): persist plex watched threshold for offline use
This commit is contained in:
@@ -52,18 +52,20 @@ class OfflineWatchSyncService extends ChangeNotifier {
|
||||
/// Get watched threshold for a server. Cascades:
|
||||
/// 1. Plex's fetched server prefs (`/:/prefs`)
|
||||
/// 2. Jellyfin's fixed [MediaServerClient.watchedThreshold] (0.9)
|
||||
/// 3. Cached value in SettingsService
|
||||
/// 3. Cached value in SettingsService (mirrored by PlexClient.fetchServerPrefs)
|
||||
/// 4. Default 90%
|
||||
double getWatchedThreshold(ServerId serverId) {
|
||||
final client = _serverManager.getClient(serverId);
|
||||
if (client is PlexClient && client.serverPrefs.isNotEmpty) {
|
||||
return client.watchedThresholdPercent / 100.0;
|
||||
return client.watchedThreshold;
|
||||
}
|
||||
if (client != null && client.backend != MediaBackend.plex) {
|
||||
// Jellyfin (and any future neutral backend) — the client exposes a
|
||||
// fixed threshold that mirrors the wire-protocol behaviour.
|
||||
return client.watchedThreshold;
|
||||
}
|
||||
// No client bound (offline) or Plex prefs not loaded yet — use the
|
||||
// mirror written on the last successful prefs fetch.
|
||||
final cached = SettingsService.instanceOrNull?.read(SettingsService.watchedThresholdPref(serverId)) ?? 90;
|
||||
return cached / 100.0;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import '../media/server_capabilities.dart';
|
||||
import '../utils/external_ids.dart';
|
||||
import 'bif_thumbnail_service.dart';
|
||||
import 'download_artwork_helpers.dart';
|
||||
import 'settings_service.dart';
|
||||
import 'library_query_translator.dart';
|
||||
import 'scrub_preview_source.dart';
|
||||
import '../utils/media_server_http_client.dart';
|
||||
@@ -1757,6 +1758,15 @@ class PlexClient
|
||||
try {
|
||||
final response = await _getWithFailover('/:/prefs');
|
||||
_serverPrefs = _parseSettingsMap(response);
|
||||
// Mirror the watched threshold to settings: offline paths resolve it
|
||||
// synchronously with no client bound — see
|
||||
// OfflineWatchSyncService.getWatchedThreshold.
|
||||
unawaited(
|
||||
SettingsService.instanceOrNull?.write(
|
||||
SettingsService.watchedThresholdPref(ServerId(serverId)),
|
||||
watchedThresholdPercent,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
appLogger.d('Failed to fetch server prefs: $e');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user