From c3cb950ffb86f581165210833941abbccfa417c8 Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Thu, 22 Oct 2026 00:47:04 +0700 Subject: [PATCH] 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. --- lib/widgets/player_lyrics.dart | 13 ++++++++++--- test/desktop_now_playing_lyrics_test.dart | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) 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);