diff --git a/lib/widgets/player_lyrics.dart b/lib/widgets/player_lyrics.dart index 5e669d8b6..5529bdc59 100644 --- a/lib/widgets/player_lyrics.dart +++ b/lib/widgets/player_lyrics.dart @@ -117,11 +117,15 @@ class _SyncedLyricsViewState extends ConsumerState /// 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 @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(() {}); } diff --git a/test/desktop_now_playing_lyrics_test.dart b/test/desktop_now_playing_lyrics_test.dart index 1094331ff..e04a21e3e 100644 --- a/test/desktop_now_playing_lyrics_test.dart +++ b/test/desktop_now_playing_lyrics_test.dart @@ -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);