mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 07:34:13 +01:00
fix: keep synced lyrics running while the window is unfocused
The synced lyrics view only followed playback while the app was resumed. On desktop, focusing another app's window makes the app inactive while its window stays on screen, so the lyrics froze on the last line until the window was focused again. An inactive app now counts as on screen, the same as a phone under a system overlay; hidden and paused still stop the view. A lifecycle change that keeps the view on screen no longer re-syncs it, so moving focus between windows leaves the lyrics running as they are.
This commit is contained in:
1 parent
44a5cd7153
commit
c3cb950ffb
2 files changed
+25
-3
No files matched your search
@@ -117,11 +117,15 @@ class _SyncedLyricsViewState extends ConsumerState<SyncedLyricsView>
|
||||
/// estimated offset, before settling on the line.
|
||||
bool _awaitingFirstScroll = false;
|
||||
bool _tickerEnabled = true;
|
||||
// An inactive app is still on screen: a desktop window behind another
|
||||
// app's window, or a phone under a system overlay.
|
||||
bool get _visible =>
|
||||
widget.isActive &&
|
||||
_tickerEnabled &&
|
||||
(WidgetsBinding.instance.lifecycleState == null ||
|
||||
WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed);
|
||||
switch (WidgetsBinding.instance.lifecycleState) {
|
||||
null || AppLifecycleState.resumed || AppLifecycleState.inactive => true,
|
||||
_ => false,
|
||||
};
|
||||
static const double _estimatedLyricExtent = 64;
|
||||
_LyricExtentSnapshot? _lineExtents;
|
||||
List<(double, double, double)> _lineMeasurements = [];
|
||||
@@ -231,7 +235,10 @@ class _SyncedLyricsViewState extends ConsumerState<SyncedLyricsView>
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
_syncPositionSubscription(resetUserScroll: false);
|
||||
// Focus moving between windows keeps the lyrics running as they are.
|
||||
if ((_positionSubscription != null) != _visible) {
|
||||
_syncPositionSubscription(resetUserScroll: false);
|
||||
}
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,21 @@ void main() {
|
||||
playback.add(pausedAt(playingLine * 3 + 1));
|
||||
await followPlayback();
|
||||
}
|
||||
// Another app's window takes focus: the lyrics stay on screen and keep
|
||||
// following playback.
|
||||
desktopInspectorPanel.value = DesktopInspectorPanel.lyrics;
|
||||
await followPlayback();
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
addTearDown(
|
||||
() => tester.binding.handleAppLifecycleStateChanged(
|
||||
AppLifecycleState.resumed,
|
||||
),
|
||||
);
|
||||
playingLine += 5;
|
||||
playback.add(pausedAt(playingLine * 3 + 1));
|
||||
await followPlayback();
|
||||
checkFrame('unfocused window');
|
||||
|
||||
// The cover column resizes with the panel but decodes its cover once.
|
||||
expect(coverWidths, hasLength(1));
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
Reference in new issue
Block a user