diff --git a/lib/services/plex_client.dart b/lib/services/plex_client.dart index b22b3f32..f8de3ae1 100644 --- a/lib/services/plex_client.dart +++ b/lib/services/plex_client.dart @@ -40,10 +40,9 @@ class LibraryContentResult { const LibraryContentResult({required this.items, required this.totalSize}); } -/// Process hub JSON response in an isolate. +/// Process hub response in an isolate. /// Top-level function so it can be passed to [Isolate.run]. -List _processHubResponse(String jsonStr, String serverId, String? serverName) { - final decoded = jsonDecode(jsonStr) as Map; +List _processHubResponse(Map decoded, String serverId, String? serverName) { final container = decoded['MediaContainer'] as Map?; if (container == null || container['Hub'] == null) return []; @@ -80,10 +79,9 @@ List _processHubResponse(String jsonStr, String serverId, String? serve return hubs; } -/// Process on-deck JSON response in an isolate. +/// Process on-deck response in an isolate. /// Top-level function so it can be passed to [Isolate.run]. -List _processOnDeckResponse(String jsonStr, String serverId, String? serverName) { - final decoded = jsonDecode(jsonStr) as Map; +List _processOnDeckResponse(Map decoded, String serverId, String? serverName) { final container = decoded['MediaContainer'] as Map?; if (container == null || container['Metadata'] == null) return []; @@ -170,6 +168,7 @@ class PlexClient { responseDecoder: _lenientUtf8Decoder, ), ); + _dio.transformer = BackgroundTransformer(); // Add interceptor for logging (optional, can be disabled in production) _dio.interceptors.add( @@ -846,13 +845,10 @@ class PlexClient { /// Get on deck items (continue watching, filtered to video content only) Future> getOnDeck() async { - final response = await _dio.get( - '/library/onDeck', - options: Options(responseType: ResponseType.plain), - ); + final response = await _dio.get('/library/onDeck'); final sid = serverId; final sname = serverName; - return Isolate.run(() => _processOnDeckResponse(response.data as String, sid, sname)); + return Isolate.run(() => _processOnDeckResponse(response.data as Map, sid, sname)); } /// Get on deck items filtered by a specific library section @@ -1325,11 +1321,10 @@ class PlexClient { final response = await _dio.get( '/hubs/sections/$sectionId', queryParameters: {'count': limit, 'includeGuids': 1}, - options: Options(responseType: ResponseType.plain), ); final sid = serverId; final sname = serverName; - return Isolate.run(() => _processHubResponse(response.data as String, sid, sname)); + return Isolate.run(() => _processHubResponse(response.data as Map, sid, sname)); } catch (e) { appLogger.e('Failed to get library hubs: $e'); } @@ -1344,11 +1339,10 @@ class PlexClient { final response = await _dio.get( '/hubs', queryParameters: {'count': limit, 'includeGuids': 1}, - options: Options(responseType: ResponseType.plain), ); final sid = serverId; final sname = serverName; - return Isolate.run(() => _processHubResponse(response.data as String, sid, sname)); + return Isolate.run(() => _processHubResponse(response.data as Map, sid, sname)); } catch (e) { appLogger.e('Failed to get global hubs: $e'); }