From a62268af7d794206c2341806f4378aaeffc65883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paal=20=C3=98ye-Str=C3=B8mme?= Date: Mon, 25 May 2026 17:23:13 +0200 Subject: [PATCH] fix(menubar): isolate currentTime reads to prevent sub-menu flicker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extract progress bar and time labels into SongProgressView struct so only that leaf view is invalidated on each lyric-tick currentTime update - MenubarWindowView no longer reads currentTime, keeping Picker sub-menus for Source Language and Target Language stable during playback Co-Authored-By: Claude Code 2.1.150 Co-Authored-By: Claude Sonnet 4.6 Signed-Off-By: Paal Øye-Strømme --- .../MenubarWindowView/MenubarWindowView.swift | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/LyricFever/Views/MenubarWindowView/MenubarWindowView.swift b/LyricFever/Views/MenubarWindowView/MenubarWindowView.swift index d27c66a..49a603b 100644 --- a/LyricFever/Views/MenubarWindowView/MenubarWindowView.swift +++ b/LyricFever/Views/MenubarWindowView/MenubarWindowView.swift @@ -9,6 +9,31 @@ import SwiftUI import LaunchAtLogin import Translation +// Isolated struct so currentTime updates don't re-render the full MenubarWindowView (which would dismiss open sub-menus). +private struct SongProgressView: View { + @Environment(ViewModel.self) var viewmodel + let lyricsEnabled: Bool + + var body: some View { + VStack(spacing: 0) { + ProgressView(value: lyricsEnabled ? viewmodel.currentTime.currentTime : 0, total: Double(viewmodel.duration)) + .progressViewStyle(ColoredThinProgressViewStyle(color: .secondary, thickness: 4)) + .frame(height: 4) + .padding(.horizontal, 4) + .environment(\.colorScheme, .dark) + + HStack { + Text(lyricsEnabled ? viewmodel.formattedCurrentTime : "--:--") + .font(.caption2) + Spacer() + Text(viewmodel.formattedDuration) + .font(.caption2) + } + .padding(.horizontal, 4) + } + } +} + struct MenubarWindowView: View { @Environment(\.openURL) var openURL @Environment(\.openWindow) var openWindow @@ -140,20 +165,8 @@ struct MenubarWindowView: View { } songControls - ProgressView(value: displayLyrics == .enabled ? viewmodel.currentTime.currentTime : 0, total: Double(viewmodel.duration)) - .progressViewStyle(ColoredThinProgressViewStyle(color: .secondary, thickness: 4)) - .frame(height: 4) - .padding(.horizontal, 4) - .environment(\.colorScheme, .dark) - - HStack { - Text(displayLyrics == .enabled ? viewmodel.formattedCurrentTime : "--:--") - .font(.caption2) - Spacer() - Text(viewmodel.formattedDuration) - .font(.caption2) - } - .padding(.horizontal, 4) + SongProgressView(lyricsEnabled: displayLyrics == .enabled) + .environment(viewmodel) } } // even out vertical padding with divider as compared to Menubar button