Trakt was the one service outside the tracker abstraction. TraktScrobbleService re-implemented the whole playback lifecycle beside TrackerCoordinator, and TraktSyncService pushed watched state from its own WatchStateNotifier subscription, so the player called two objects at every lifecycle point and one watch could be written twice. TraktTracker now implements RealtimeScrobbleTracker like Simkl; the duplicated player call sites collapse to one each, and Trakt shares the coordinator's ID resolver instead of re-fetching show ids every episode. Capabilities are split so a tracker declares what it is rather than being special-cased: ScrobblePolicy carries each service's own resend/seek rules, EpisodeHistoryTracker names the remote row a per-item history write targets, and SeriesProgressTracker covers one-counter-per-series services. Writes from all four trackers go through a shared TrackerWriteQueue, generalised from the Trakt-only queue, with the legacy Trakt payload migrated on load. Trakt becomes the fourth TrackersProvider slot and TraktAccountProvider is deleted, so one object owns the active session per profile. Two failure paths found while consolidating are fixed here too. The queue's retries only ran on profile bind, connect and app foreground, so a network blip mid-session left queued watches waiting for the next foreground. OfflineModeProvider now notifies on connectivity changes, not just offline-state or WiFi-flag changes, and main.dart flushes the queue when the network returns. The queue also counted every failure toward the five attempts that permanently drop an item, so a rate limit or a service having a bad hour could discard a pending watch - the loss the queue exists to prevent. Only an answer about the write itself now spends an attempt: 4xx counts, while rate limits, 5xx, recoverable token-refresh failures and requests that never arrived do not. A back-off answer also defers that service for the rest of the flush, so a queue holding many rows does not fire all of them at a service that just asked for quiet.
93 lines
3.5 KiB
Dart
93 lines
3.5 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../i18n/strings.g.dart';
|
|
import '../../models/catalog/catalog_item.dart';
|
|
import '../../providers/trackers_provider.dart';
|
|
import '../../services/trackers/anilist/anilist_tracker.dart';
|
|
import '../../services/trackers/mal/mal_tracker.dart';
|
|
import '../../services/trackers/simkl/simkl_tracker.dart';
|
|
import '../../services/trackers/tracker.dart';
|
|
import '../../services/trackers/tracker_constants.dart';
|
|
import '../../services/trackers/trakt/trakt_tracker.dart';
|
|
import 'tracker_settings_screen.dart';
|
|
import 'trakt_settings_screen.dart';
|
|
|
|
/// One watch tracker, described once for every place that lists services: the
|
|
/// services hub, the rating sheet, and the settings summary line.
|
|
///
|
|
/// [isConnected] and [username] take a [BuildContext] and read the account
|
|
/// state with `watch`, so the calling element rebuilds exactly like the
|
|
/// per-service `Consumer` these entries replaced.
|
|
class TrackerServiceInfo {
|
|
final TrackerService service;
|
|
final String displayName;
|
|
|
|
/// Which brand mark to draw; the asset path itself lives only in
|
|
/// `CatalogSourceLogo`.
|
|
final CatalogSourceId logoSource;
|
|
|
|
final TrackerRatingSource ratingSource;
|
|
final bool Function(BuildContext) isConnected;
|
|
final String? Function(BuildContext) username;
|
|
final Future<void> Function(BuildContext) startConnection;
|
|
final Widget Function() buildSettingsScreen;
|
|
|
|
const TrackerServiceInfo({
|
|
required this.service,
|
|
required this.displayName,
|
|
required this.logoSource,
|
|
required this.ratingSource,
|
|
required this.isConnected,
|
|
required this.username,
|
|
required this.startConnection,
|
|
required this.buildSettingsScreen,
|
|
});
|
|
|
|
/// Entry for a service that shares [TrackerSettingsScreen]: [config] already
|
|
/// carries the name and the [TrackersProvider] accessors.
|
|
TrackerServiceInfo.shared(
|
|
TrackerConfig config, {
|
|
required this.logoSource,
|
|
required this.ratingSource,
|
|
required this.startConnection,
|
|
}) : service = config.service,
|
|
displayName = config.displayName,
|
|
isConnected = ((context) => config.isConnected(context.watch<TrackersProvider>())),
|
|
username = ((context) => config.username(context.watch<TrackersProvider>())),
|
|
buildSettingsScreen = (() => TrackerSettingsScreen(config: config));
|
|
|
|
/// Display order shared by every list. Built per call because [displayName]
|
|
/// reads the active locale.
|
|
static List<TrackerServiceInfo> get all => [
|
|
TrackerServiceInfo(
|
|
service: TrackerService.trakt,
|
|
displayName: t.trakt.title,
|
|
logoSource: CatalogSourceId.trakt,
|
|
ratingSource: TraktTracker.instance,
|
|
isConnected: (context) => context.watch<TrackersProvider>().isTraktConnected,
|
|
username: (context) => context.watch<TrackersProvider>().traktUsername,
|
|
startConnection: startTraktConnection,
|
|
buildSettingsScreen: () => const TraktSettingsScreen(),
|
|
),
|
|
TrackerServiceInfo.shared(
|
|
TrackerConfig.mal(),
|
|
logoSource: CatalogSourceId.mal,
|
|
ratingSource: MalTracker.instance,
|
|
startConnection: startMalConnection,
|
|
),
|
|
TrackerServiceInfo.shared(
|
|
TrackerConfig.anilist(),
|
|
logoSource: CatalogSourceId.anilist,
|
|
ratingSource: AnilistTracker.instance,
|
|
startConnection: startAnilistConnection,
|
|
),
|
|
TrackerServiceInfo.shared(
|
|
TrackerConfig.simkl(),
|
|
logoSource: CatalogSourceId.simkl,
|
|
ratingSource: SimklTracker.instance,
|
|
startConnection: startSimklConnection,
|
|
),
|
|
];
|
|
}
|