Skip to content

Commit

Permalink
Ensure tab state is torn down on window close (#3364)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1201048563534612/1208463834186044/f

**Description**:

For some weeks we've had reports about music playing after a browser
window playing music is closed. Turns out an indirect reference to the
WebView was being held through the `ActiveDomainPublisher` introduced
during #3076. I've made
an attempt at fixing this, but lemme know if there's a better way.

**Steps to test this PR**:
1. Open a single browser window.
2. Go to soundcloud.com and start any music playing
3. Close the window
**4. Music should stop playing**

**Definition of Done**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
  • Loading branch information
graeme authored Oct 8, 2024
1 parent ef9d7fe commit 78caeb3
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class ActiveDomainPublisher {
private var activeWindowControllerCancellable: AnyCancellable?
private var activeTabViewModelCancellable: AnyCancellable?
private var activeTabContentCancellable: AnyCancellable?
private var unregisterWindowControllerCancellable: AnyCancellable?

@MainActor private weak var activeWindowController: MainWindowController? {
didSet {
Expand All @@ -47,6 +48,7 @@ final class ActiveDomainPublisher {

Task { @MainActor in
subscribeToKeyWindowControllerChanges()
subscribeToUnregisteringWindowController()
}
}

Expand Down Expand Up @@ -76,6 +78,16 @@ final class ActiveDomainPublisher {
.assign(to: \.activeDomain, onWeaklyHeld: self)
}

@MainActor
private func subscribeToUnregisteringWindowController() {
unregisterWindowControllerCancellable = windowControllersManager.didUnregisterWindowController.sink { [weak self] in
guard let self else { return }
if self.activeWindowController == $0 {
self.activeWindowController = nil
}
}
}

private func domain(from tabContent: Tab.TabContent) -> String? {
if case .url(let url, _, _) = tabContent {

Expand Down

0 comments on commit 78caeb3

Please sign in to comment.