Commit 51888639 authored by Kourser's avatar Kourser
Browse files

fix(macos): stop the episodes popover from dismissing itself

The popover appeared then vanished immediately. Two timing hazards
around its presentation are removed:

- The scrubber selection reset no longer runs right after showPopover
  (mutating a control of the collapsed bar could re-present it); both
  scrubbers now reset when the popover closes, in returnToLibrary.
- The popover is presented after a 250 ms beat, letting the app finish
  navigating to the podcast page (the synced detail-pane change was
  churning the responder chain under the fresh popover).

Co-Authored-By: Claude (RCA)
parent ba4b004d
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -81,7 +81,14 @@ final class TouchBarController: NSObject {
                self.episodeScrubber?.reloadData()
            }
        }
        if let popover = episodesPopover, !popover.popoverTouchBar.isVisible {
        // Deferred presentation: opening synchronously raced with the app's
        // own navigation to the podcast page (responder churn dismissed the
        // popover right after it appeared).
        Task { @MainActor [weak self] in
            try? await Task.sleep(for: .milliseconds(250))
            guard let self, self.episodesPodcastID == podcast.id,
                  let popover = self.episodesPopover,
                  !popover.popoverTouchBar.isVisible else { return }
            popover.showPopover(nil)
        }
    }
@@ -96,6 +103,10 @@ final class TouchBarController: NSObject {
        if let popover = episodesPopover, popover.popoverTouchBar.isVisible {
            popover.dismissPopover(nil)
        }
        // Selections reset here, once the popover is closed — mutating the
        // scrubbers around the presentation dismissed it.
        podcastScrubber?.selectedIndex = -1
        episodeScrubber?.selectedIndex = -1
    }

    // MARK: Observation (re-armed after each change)
@@ -296,11 +307,6 @@ extension TouchBarController: NSScrubberDataSource, NSScrubberDelegate,
    }

    func scrubber(_ scrubber: NSScrubber, didSelectItemAt index: Int) {
        // Allow re-tapping the same item — reset after the touch settles,
        // not synchronously inside the gesture callback.
        defer {
            Task { @MainActor in scrubber.selectedIndex = -1 }
        }
        if scrubber === episodeScrubber {
            guard episodes.indices.contains(index) else { return }
            let episode = episodes[index]