feat(player): resume last session on launch (#54)
The #52 teardown clears the session when idle/dismissed, so the headset / lock-screen play button had nothing to resume and the user lost their place. - track.dart: toJson() (round-trips fromJson) - db.dart: CachedResumeState single-row snapshot, schema 9->10 + migration - audio_handler.dart: queuedTracks getter - player_provider.dart: restoreQueue() — configure + setQueueFromTracks + seek, no play (restores PAUSED) - resume_controller.dart: restores last snapshot paused on launch; persists {source,index,position_ms,tracks} debounced on track change / pause and immediately on app teardown; never clobbers the saved snapshot when the queue is empty so a teardown stays recoverable; restore gated on auth + no active session - app.dart: wired into postFrame db.g.dart regenerated by CI per project convention. Deferred fast-follow: media-button-when-fully-stopped re-init (needs a configure()-injected callback; tracked on #54). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vendored
+22
-1
@@ -230,6 +230,20 @@ class CachedQuarantineMine extends Table {
|
||||
Set<Column> get primaryKey => {trackId};
|
||||
}
|
||||
|
||||
/// Single-row snapshot of the last playback session — queue (TrackRef
|
||||
/// JSON), current index, position, and #415 source. Lets a torn-down
|
||||
/// session (the #52 idle/dismissed teardown) resume on next launch;
|
||||
/// without it the headset / lock-screen play button has nothing to
|
||||
/// resume. Mirrors the CachedHomeSnapshot single-row JSON pattern.
|
||||
/// Schema 10+.
|
||||
class CachedResumeState extends Table {
|
||||
IntColumn get id => integer().withDefault(const Constant(1))();
|
||||
TextColumn get json => text()();
|
||||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||||
@override
|
||||
Set<Column> get primaryKey => {id};
|
||||
}
|
||||
|
||||
enum CacheSource { manual, autoLiked, autoPlaylist, autoPrefetch, incidental }
|
||||
|
||||
@DriftDatabase(tables: [
|
||||
@@ -247,12 +261,13 @@ enum CacheSource { manual, autoLiked, autoPlaylist, autoPrefetch, incidental }
|
||||
CachedHomeIndex,
|
||||
CachedSystemPlaylistsStatus,
|
||||
CachedMutations,
|
||||
CachedResumeState,
|
||||
])
|
||||
class AppDb extends _$AppDb {
|
||||
AppDb([QueryExecutor? e]) : super(e ?? driftDatabase(name: 'minstrel_cache'));
|
||||
|
||||
@override
|
||||
int get schemaVersion => 9;
|
||||
int get schemaVersion => 10;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
@@ -316,6 +331,12 @@ class AppDb extends _$AppDb {
|
||||
'UPDATE audio_cache_index SET last_played_at = cached_at',
|
||||
);
|
||||
}
|
||||
if (from < 10) {
|
||||
// Schema 10 (#54): cached_resume_state — single-row last-
|
||||
// session snapshot for resume-on-launch. Empty on upgrade;
|
||||
// first persist populates it.
|
||||
await m.createTable(cachedResumeState);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user