The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
A WebKit video played again within 2 s of a pause shows as playing in the sidebar player
Victor9da50e7a6c71
diff --git a/Packages/CraCore/Sources/CraCore/AudibleHold.swift b/Packages/CraCore/Sources/CraCore/AudibleHold.swiftnew file mode 100644index 0000000..04ef0b8--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/AudibleHold.swift@@ -0,0 +1,45 @@+import Foundation++/// A WebKit tab's audible state as Chrome keeps it: on as sound starts, off only after `quiet`+/// seconds without sound, so a track change doesn't blink the tab's speaker or the sidebar's+/// now-playing card. WebKitBrowser feeds it WebKit's "playing audio" and tells its delegate+/// what each step says.+public struct AudibleHold: Equatable, Sendable {+ /// Chrome's AudioStreamMonitor holds a tab audible this long after its sound stops.+ public static let quiet: TimeInterval = 2++ /// What the tab does after a change of the page's sound.+ public enum Step: Equatable, Sendable {+ /// Tell the delegate the tab is audible.+ case announce+ /// Call `quietEnded()` after `quiet` seconds, unless sound comes back first.+ case holdThenQuiet+ case nothing+ }++ public private(set) var playing = false+ public private(set) var audible = false++ public init() {}++ /// The page's sound started or stopped. Sound coming back within the hold is announced+ /// again though the tab never went quiet: a pause from the sidebar's card has the card show+ /// paused already, and it learns of the page playing again only this way.+ public mutating func setPlaying(_ now: Bool) -> Step {+ let was = playing+ playing = now+ if now {+ guard !audible || !was else { return .nothing }+ audible = true+ return .announce+ }+ return audible ? .holdThenQuiet : .nothing+ }++ /// The hold ran out. True: tell the delegate the tab went quiet.+ public mutating func quietEnded() -> Bool {+ guard !playing, audible else { return false }+ audible = false+ return true+ }+}diff --git a/Packages/CraCore/Tests/CraCoreTests/AudibleHoldTests.swift b/Packages/CraCore/Tests/CraCoreTests/AudibleHoldTests.swiftnew file mode 100644index 0000000..cbfa307--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/AudibleHoldTests.swift@@ -0,0 +1,61 @@+import CraCore+import Testing++/// A WebKit tab's speaker and now-playing card: on as sound starts, off 2 s after it stops.+struct AudibleHoldTests {+ @Test func soundStartingAnnouncesTheTab() {+ var hold = AudibleHold()+ let r1 = hold.setPlaying(true)+ #expect(r1 == .announce)+ #expect(hold.audible)+ }++ @Test func soundStoppingGoesQuietOnlyAfterTheHold() {+ var hold = AudibleHold()+ _ = hold.setPlaying(true)+ let r2 = hold.setPlaying(false)+ #expect(r2 == .holdThenQuiet)+ #expect(hold.audible, "still audible during the hold")+ let r3 = hold.quietEnded()+ #expect(r3)+ #expect(!hold.audible)+ }++ /// A track change: sound stops and starts again within the hold, and the speaker stays on.+ @Test func soundBackWithinTheHoldStaysAudible() {+ var hold = AudibleHold()+ _ = hold.setPlaying(true)+ _ = hold.setPlaying(false)+ _ = hold.setPlaying(true)+ let q = hold.quietEnded()+ #expect(!q, "the stale hold doesn't silence a playing tab")+ #expect(hold.audible)+ }++ /// Paused from the sidebar's card (which then shows paused) and played again on the page+ /// within 2 s: the card has to hear the tab plays again, though it never went quiet. Before,+ /// the card stayed on paused while the video played (nightly webkit-drm-tabs, 6 Nov 2026).+ @Test func soundBackWithinTheHoldIsAnnouncedAgain() {+ var hold = AudibleHold()+ _ = hold.setPlaying(true)+ _ = hold.setPlaying(false)+ let r4 = hold.setPlaying(true)+ #expect(r4 == .announce)+ }++ /// WebKit repeats "playing" while it plays: one announcement per start, not per report.+ @Test func repeatedPlayingReportsAnnounceOnce() {+ var hold = AudibleHold()+ _ = hold.setPlaying(true)+ let r5 = hold.setPlaying(true)+ #expect(r5 == .nothing)+ }++ @Test func silenceFromTheStartDoesNothing() {+ var hold = AudibleHold()+ let r6 = hold.setPlaying(false)+ #expect(r6 == .nothing)+ let q = hold.quietEnded()+ #expect(!q)+ }+}diff --git a/Sources/Cra/Services/WebKit/WebKitBrowser.swift b/Sources/Cra/Services/WebKit/WebKitBrowser.swiftindex 647c173..d4343ad 100644--- a/Sources/Cra/Services/WebKit/WebKitBrowser.swift+++ b/Sources/Cra/Services/WebKit/WebKitBrowser.swift@@ -35,8 +35,7 @@ final class WebKitBrowser: CraBrowser, WKNavigationDelegate, WKUIDelegate, WKDowprivate var lastLoadingState: [Bool] = []private var observations: [NSKeyValueObservation] = []private var observesPlayingAudio = false- private var playing = false- private var audible = false+ private var audibleHold = AudibleHold()private var audibleOff: DispatchWorkItem?private var capturing = false/// The service this page opened for ("Spotify"), kept while it signs in elsewhere: what the@@ -221,7 +220,7 @@ final class WebKitBrowser: CraBrowser, WKNavigationDelegate, WKUIDelegate, WKDowoverride var isInPictureInPicture: Bool { inPictureInPicture }override var isPictureInPicturePlaying: Bool { pictureInPicturePlaying }override var isCapturingMedia: Bool { capturing }- override var isAudible: Bool { audible }+ override var isAudible: Bool { audibleHold.audible }/// Once per change of the three, as CEF's OnLoadingStateChange (each of them is observed).@MainActor@@ -242,26 +241,25 @@ final class WebKitBrowser: CraBrowser, WKNavigationDelegate, WKUIDelegate, WKDowdelegate?.browser?(self, didChangeMediaCapture: now)}- /// Chrome's audible state: on as sound starts, off 2 s after it stops.+ /// Chrome's audible state: on as sound starts, off 2 s after it stops (AudibleHold).@MainActorprivate func setPlaying(_ now: Bool) {- playing = nowaudibleOff?.cancel()audibleOff = nil- if now {- guard !audible else { return }- audible = true+ switch audibleHold.setPlaying(now) {+ case .announce:delegate?.browser?(self, didChangeAudible: true)- } else if audible {+ case .holdThenQuiet:let work = DispatchWorkItem { [weak self] inMainActor.assumeIsolated {- guard let self, !self.playing, self.audible, !self.closed else { return }- self.audible = false+ guard let self, !self.closed, self.audibleHold.quietEnded() else { return }self.delegate?.browser?(self, didChangeAudible: false)}}audibleOff = work- DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: work)+ DispatchQueue.main.asyncAfter(deadline: .now() + AudibleHold.quiet, execute: work)+ case .nothing:+ break}}