fix(offline): persist plex watched threshold for offline use

This commit is contained in:
edde746
2026-06-12 13:43:29 +02:00
parent 05251edaf3
commit 75d0164a8b
2 changed files with 14 additions and 2 deletions
+4 -2
View File
@@ -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;
}
+10
View File
@@ -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');
}