3054e8702b
The Flutter client previously reported NO plays — mobile listening never reached play_events, so history, recommendation scoring, ListenBrainz scrobbles, and #415 rotation all missed mobile entirely. Operator chose to close that gap properly as part of Stage 3. New: - EventsApi (api/endpoints/events.dart): play_started/ended/skipped. - PlayEventsReporter (player/play_events_reporter.dart): state machine over (track id, playing) mirroring the web dispatcher. Persists an opaque client_id in secure storage. Deliberate divergence from web: a track change inside a queue is classified ended-vs-skipped by whether the prior track reached ~its duration (3s tolerance), instead of web's blanket "track change = skip" which would mark every naturally-finished in-queue track a skip and dilute recommendation skip-ratios — the exact failure mode that motivated doing this properly. Fail-safe: no-ops when there's no audio handler (tests / no-audio env). App-lifecycle paused/ detached closes an open row as a best-effort skip (web pagehide parity). Wired in app.dart postFrame. - PlaylistsApi.systemShuffle(variant): GET the rotation-aware order. Wiring: - audio_handler: _queueSource carried through setQueueFromTracks (source param); preserved across internal skipToQueueItem rebuild. - player_provider.playTracks: source param → setQueueFromTracks. - PlaylistCard: system playlists fetch systemShuffle and play as-is tagged with source (no client shuffle — server already ordered). - playlist_detail_screen: header Play + per-track tap tag source for system playlists so rotation advances from any entry point. Known/flagged separately: the web dispatcher likely has the same false-skip-on-advance issue; not fixed here to keep #415 scoped and clients' wire behavior comparable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
80 lines
3.3 KiB
Dart
80 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'cache/cache_filler.dart';
|
|
import 'cache/metadata_prefetcher.dart';
|
|
import 'cache/mutation_queue.dart';
|
|
import 'cache/prefetcher.dart';
|
|
import 'cache/sync_controller.dart';
|
|
import 'player/play_events_reporter.dart';
|
|
import 'shared/live_events_dispatcher.dart';
|
|
import 'shared/routing.dart';
|
|
import 'theme/theme_data.dart';
|
|
import 'theme/theme_mode_provider.dart';
|
|
|
|
class MinstrelApp extends ConsumerStatefulWidget {
|
|
const MinstrelApp({super.key});
|
|
|
|
@override
|
|
ConsumerState<MinstrelApp> createState() => _MinstrelAppState();
|
|
}
|
|
|
|
class _MinstrelAppState extends ConsumerState<MinstrelApp> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Activate offline-mode infrastructure once the first frame ships.
|
|
// SyncController.sync() is connectivity-aware (no-ops on no auth /
|
|
// no server URL), so calling it unconditionally is safe.
|
|
// Reading prefetcherProvider runs its constructor, which wires the
|
|
// queue + settings listeners.
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
// ignore: unawaited_futures
|
|
ref.read(syncControllerProvider.notifier).sync();
|
|
ref.read(prefetcherProvider);
|
|
// Metadata prefetcher: when /api/home returns, fire background
|
|
// albumProvider/artistProvider reads for the top-N items in
|
|
// each section so subsequent taps are drift hits, not network
|
|
// round trips.
|
|
ref.read(metadataPrefetcherProvider);
|
|
// Live events (#392): subscribes to /api/events/stream and
|
|
// invalidates publicly-scoped providers when relevant events
|
|
// arrive. Also installs an AppLifecycleState observer for
|
|
// resume-time defensive invalidation.
|
|
ref.read(liveEventsDispatcherProvider);
|
|
// Cache filler: background sweeper that walks cached_artists
|
|
// / cached_albums for missing relations and fetches the
|
|
// per-entity detail so tapping an artist surfaces albums
|
|
// immediately (drift hit, no /api/artists/:id round-trip at
|
|
// tap time). First sweep 10s after launch; every 5 minutes
|
|
// thereafter. Throttled 200ms between requests so it never
|
|
// competes with user activity.
|
|
ref.read(cacheFillerProvider);
|
|
// Mutation replayer: drains the cached_mutations queue when
|
|
// connectivity comes back. Controllers (LikesController,
|
|
// MyQuarantineController, the add-to-playlist + request flows)
|
|
// enqueue on REST failure so user intent persists across
|
|
// network loss instead of getting rolled back.
|
|
ref.read(mutationReplayerProvider);
|
|
// Play-events reporter (#415): the Flutter client otherwise
|
|
// reports no plays at all — this feeds history, recommendation
|
|
// scoring, scrobbles, and system-playlist rotation, and is the
|
|
// path that carries the `source` tag for #415.
|
|
ref.read(playEventsReporterProvider);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final router = ref.watch(routerProvider);
|
|
final mode = ref.watch(themeModeProvider).value ?? AppThemeMode.system;
|
|
return MaterialApp.router(
|
|
title: 'Minstrel',
|
|
theme: buildLightTheme(),
|
|
darkTheme: buildDarkTheme(),
|
|
themeMode: mode.materialMode,
|
|
routerConfig: router,
|
|
);
|
|
}
|
|
}
|