Commit 374de360 authored by Kourser's avatar Kourser
Browse files

fix(macos): episode strip could bind its data source before its identity

In the episodes item, the scrubber's data source was wired before the
episodeScrubber reference was assigned: if the control queries during
configuration, the identity check in numberOfItems/viewForItemAt takes
the podcasts branch and the strip renders garbage/empty. The identity
is now assigned first and the data source connected last, with a
defensive reload once materialized (content can arrive first) and two
NSLog diagnostics to finally see the sequencing on-device from Xcode's
console if anything else remains.

Co-Authored-By: Claude (RCA)
parent ba5c6496
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -160,6 +160,9 @@ 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()
            }
        }
@@ -317,14 +320,24 @@ extension TouchBarController: NSTouchBarDelegate {
            return item
        case .skingomzEpisodes:
            let item = NSCustomTouchBarItem(identifier: identifier)
            let scrubber = makeScrubber()
            let scrubber = NSScrubber()
            // Identity FIRST: the data-source callbacks compare against this
            // reference, and the control may query while being configured.
            episodeScrubber = scrubber
            scrubber.register(NSScrubberTextItemView.self, forItemIdentifier: Self.episodeCell)
            scrubber.scrubberLayout = NSScrubberFlowLayout() // sized per title below
            scrubber.mode = .free
            scrubber.selectionOverlayStyle = .outlineOverlay
            scrubber.showsAdditionalContentIndicators = true
            let stretch = scrubber.widthAnchor.constraint(equalToConstant: 1200)
            stretch.priority = .defaultLow
            stretch.isActive = true
            item.view = scrubber
            episodeScrubber = 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
        default:
            return nil