Commit 7136564c authored by Kourser's avatar Kourser
Browse files

fix(macos): show the playing bar right after launching an episode

Tapping an episode nulled the synced podcast id so re-tapping the same
artwork would drill in again — but the podcast page is still open in
the app, so the very next refresh (fired by playback starting) saw a
'new' visible podcast and re-opened the episode level over the playing
bar; it only surfaced after navigating away. The synced id now stays
put, and the re-tap case is handled explicitly (same page open -> drill
in directly). Diagnostic NSLogs removed now that the flow is confirmed.

Co-Authored-By: Claude (RCA)
parent 7ac0be90
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -160,15 +160,7 @@ final class TouchBarController: NSObject {
                let list = await self.model.episodes(for: podcast)
                guard self.episodesPodcastID == podcast.id else { return }
                self.episodes = Array(list.prefix(16))
                NSLog("[TouchBar] episodes loaded: %d for %@ (scrubber: %@)",
                      self.episodes.count, podcast.title,
                      self.episodeScrubber == nil ? "absent" : "présent")
                self.episodeScrubber?.reloadData()
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
                    guard let scrubber = self?.episodeScrubber else { return }
                    NSLog("[TouchBar] episodes frame: %@ (items affichés : %d)",
                          NSStringFromRect(scrubber.frame), scrubber.numberOfItems)
                }
            }
        }
        applyLevel()
@@ -342,7 +334,6 @@ extension TouchBarController: NSTouchBarDelegate {
            item.view = scrubber
            scrubber.dataSource = self
            scrubber.delegate = self
            NSLog("[TouchBar] episode scrubber materialized (episodes: %d)", episodes.count)
            // Defensive: content may have arrived before materialization.
            DispatchQueue.main.async { scrubber.reloadData() }
            return item
@@ -413,14 +404,18 @@ extension TouchBarController: NSScrubberDataSource, NSScrubberDelegate,
            let episode = episodes[index]
            Task { await model.play(episode) }
            // Back to the now-playing level; the app stays on the podcast
            // page. Forget the synced id so re-tapping the artwork drills in.
            // page (the synced id must stay put, or the next refresh would
            // re-open the episode level over the playing bar).
            returnToLibrary()
            syncedPodcastID = nil
        } else {
            guard podcasts.indices.contains(index) else { return }
            let podcast = podcasts[index]
            if podcast.isRadio {
                commands.openPodcastID = podcast.id // plays the station
            } else if commands.visiblePodcastID == podcast.id {
                // Same page already open in the app (e.g. re-tapping after
                // launching an episode): re-drill directly.
                showEpisodes(of: podcast)
            } else {
                // Shared state: opens the page in the app AND our episode
                // level (via the observation-driven sync).