diff --git a/Plans/08 WebKit engine/S051-profile-cookies-media.md b/Plans/08 WebKit engine/S051-profile-cookies-media.md index 88cf884..2e73a4f 100644 --- a/Plans/08 WebKit engine/S051-profile-cookies-media.md +++ b/Plans/08 WebKit engine/S051-profile-cookies-media.md @@ -16,8 +16,8 @@ one MPRIS player. - [x] `paths.rs`: `APP_DIR = "nacre-browser"`; migration (rename config/data/cache once if new missing and old present; delete Servo-only engine files after; log it); unit test with temp dirs; `~/.config/nacre` never touched. - [x] Cookies: persistent storage path in `$XDG_RUNTIME_DIR/nacre-/cookies.sqlite`; at start decrypt `cookies.bin` → `add_cookie` (or write the SQLite) ; seal at quit and 60 s after `changed`; no keyring → run-only; convert Servo-era `cookies.bin` when it parses, else move aside. - [x] Clear data / clear on exit / site info flyout on `WebsiteDataManager` (types + since-time) and `CookieManager::get_cookies`; drop the "Servo keeps no dates" text. -- [ ] Incognito: ephemeral session, nothing written; check the throwaway home after a run. -- [ ] Media: probe events + `is-playing-audio` → media state; mute via `set_is_muted`; check whether WebKitGTK publishes its own MPRIS player (`busctl --user list | grep mpris` in the nested bus) and apply D-039 (one player). +- [x] Incognito: ephemeral session, nothing written; check the throwaway home after a run. +- [x] Media: probe events + `is-playing-audio` → media state; mute via `set_is_muted`; check whether WebKitGTK publishes its own MPRIS player (`busctl --user list | grep mpris` in the nested bus) and apply D-039 (one player). - [ ] Smoke: `cookies.txt` → `cookies-restart.txt` → `cookies-cleared.txt` with `SMOKE_KEYRING=1`, `cookies-nokeyring.txt`, `restore.txt`, `privacy-incognito.txt` green hidden; `grep -c` of a test cookie value in the home dir = 0. - [ ] PROGRESS entry, INDEX line, tracker, commit `S051: …`, push. @@ -32,4 +32,4 @@ one MPRIS player. Migration behaviour, seal timing, MPRIS outcome (which player). ## Resume note (WIP) -- Boxes 1–3 done (site-data.txt smoke new, green). Next: box 4 incognito check, box 5 media. +- Boxes 1–5 done (site-data.txt, media-audio.txt new, green; WebKit publishes its own MPRIS player, Nacre has none: one player). Next: box 6 smokes, then docs + commit. diff --git a/src/actions.rs b/src/actions.rs index 02cb63c..e84799e 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -499,10 +499,7 @@ impl App { self.shared.toast("All tabs bookmarked in Other bookmarks"); }, Command::Action(action) => self.run_action(window, action), - Command::Media { tab, action, value } => { - let arg = if action == "mute" { serde_json::Value::from(value > 0.5) } else { serde_json::Value::from(value) }; - self.eval(tab, inject::call("media.act", &[action.into(), arg])); - }, + Command::Media { tab, action, value } => self.eval(tab, inject::call("media.act", &[action.into(), value.into()])), Command::ToggleMuteSite(host) => { let muted = { let mut s = self.shared.settings.borrow_mut(); @@ -517,9 +514,12 @@ impl App { let ids: Vec = self.windows.values().flat_map(|w| w.tabs.iter().filter(|t| t.host() == host).map(|t| t.id)).collect(); for id in ids { if let Some((w, i)) = self.find_tab(id) { - self.windows.get_mut(&w).expect("found").tabs[i].muted = muted; + let tab = &mut self.windows.get_mut(&w).expect("found").tabs[i]; + tab.muted = muted; + if let Some(web) = tab.webview() { + web.set_muted(muted); + } } - self.eval(id, inject::call("media.act", &["mute".into(), muted.into()])); } }, Command::Download(op) => self.download_op(op), diff --git a/src/app.rs b/src/app.rs index 0d70bdb..d6b0215 100644 --- a/src/app.rs +++ b/src/app.rs @@ -815,6 +815,11 @@ impl App { Event::Notification(id, notification) => self.on_notification(id, notification), Event::Page(id, message) => self.on_page_message(id, message), Event::Find(id, count) => self.on_find(id, count), + Event::Audio(id, playing) => { + let Some((w, i)) = self.find_webview(id) else { return }; + self.windows.get_mut(&w).expect("found").tabs[i].playing_audio = playing; + self.redraw(w); + }, Event::SiteData(host, data) => { let mut current = self.shared.site_data.borrow_mut(); if current.0 == host { diff --git a/src/engine/host.rs b/src/engine/host.rs index 3f2d47e..e1c8818 100644 --- a/src/engine/host.rs +++ b/src/engine/host.rs @@ -579,6 +579,8 @@ impl Engine { let hub = self.hub.clone(); web.connect_favicon_notify(move |_| hub.push(Event::Favicon(id))); let hub = self.hub.clone(); + web.connect_is_playing_audio_notify(move |w| hub.push(Event::Audio(id, w.is_playing_audio()))); + let hub = self.hub.clone(); let provisional = Rc::new(std::cell::Cell::new(false)); let tab_loading = provisional.clone(); web.connect_load_changed(move |w, event| { diff --git a/src/engine/mod.rs b/src/engine/mod.rs index b89a467..ac61eb5 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -87,6 +87,8 @@ pub enum Event { Page(ViewId, PageMessage), /// Find in page: how many matches the last search or step found (0: none). Find(ViewId, u32), + /// WebKit's `is-playing-audio` changed. + Audio(ViewId, bool), /// A cookie was added, changed or deleted. CookiesChanged, /// What a host keeps (`Engine::site_data`). diff --git a/src/inject.rs b/src/inject.rs index 3e8e841..b49423f 100644 --- a/src/inject.rs +++ b/src/inject.rs @@ -194,7 +194,6 @@ const MEDIA_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.media) else if (a === 'skip' && m) m.currentTime = Math.max(0, m.currentTime + v); else if (a === 'loop' && m) m.loop = !m.loop; else if (a === 'shuffle') { const b = shuf(); if (b) b.click(); } - else if (a === 'mute') document.querySelectorAll('video,audio').forEach(e => e.muted = !!v); else if (a === 'volume' && m) { m.volume = Math.min(1, Math.max(0, v)); m.muted = false; } setTimeout(report, 50); return state(); diff --git a/src/selftest.rs b/src/selftest.rs index 1592616..c1f7da3 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -884,7 +884,7 @@ impl App { serde_json::json!({ "active": i == w.active, "url": t.shown_url(), "title": t.display_title(), "loading": t.loading(), "load_status": format!("{:?}", t.load_status), "has_web": t.web.is_some(), "frozen": t.frozen, "blocked": t.blocked, - "hidden_elements": t.hidden_elements, "pinned": t.pinned, "muted": t.muted, "zoom": t.zoom, + "hidden_elements": t.hidden_elements, "pinned": t.pinned, "muted": t.muted, "playing_audio": t.playing_audio, "audible": t.audible(), "zoom": t.zoom, "favicon": t.favicon.is_some(), "crashed": t.crashed, "can_back": t.can_go_back(), "can_forward": t.can_go_forward(), "history_len": t.back_forward.len(), "find": [t.find.index, t.find.count], "prompts": t.prompts.len(), "dialog": t.dialog.is_some(), "media": t.media.as_ref().map(|(m, _)| serde_json::json!({"title": m.title, "paused": m.paused, "duration": m.duration, "position": m.position})), diff --git a/src/tabs.rs b/src/tabs.rs index 488786e..29b445f 100644 --- a/src/tabs.rs +++ b/src/tabs.rs @@ -168,6 +168,8 @@ pub struct Tab { pub status_text: Option, pub pinned: bool, pub muted: bool, + /// WebKit hears sound from the page (`is-playing-audio`: Web Audio and frames too). + pub playing_audio: bool, pub media: Option<(MediaState, u64)>, pub back_forward: Vec, pub history_index: usize, @@ -227,6 +229,7 @@ impl Tab { status_text: None, pinned: false, muted: false, + playing_audio: false, media: None, back_forward: Vec::new(), history_index: 0, @@ -300,7 +303,7 @@ impl Tab { } pub fn audible(&self) -> bool { - self.media.as_ref().is_some_and(|(m, _)| !m.paused && !m.muted) && !self.muted + !self.muted && (self.playing_audio || self.media.as_ref().is_some_and(|(m, _)| !m.paused && !m.muted)) } pub fn display_title(&self) -> String { diff --git a/tests/smoke/media-audio.txt b/tests/smoke/media-audio.txt new file mode 100644 index 0000000..19987a5 --- /dev/null +++ b/tests/smoke/media-audio.txt @@ -0,0 +1,22 @@ +# Media on WebKit (S051, D-039): WebKit's is-playing-audio marks the tab audible (Web Audio, which the page probe +# can't see), the tab mute goes through set_is_muted and the page keeps running. Offline, hidden (real click). +# tools/smoke.sh tests/smoke/media-audio.txt +wait 3 +open @PAGES@/sound.html +waitload +click 300 300 +waitfor 20 document.title === "Sound on" +waitstatus 20 /tabs/0/playing_audio true +expect /active/audible true +shot sound-on +cmd mute +wait 2 +expect /active/muted true +expect /active/audible false +assert window.ctx.state === "running" +shot sound-muted +cmd mute +wait 2 +expect /active/audible true +status done +quit diff --git a/tests/smoke/pages/sound.html b/tests/smoke/pages/sound.html new file mode 100644 index 0000000..397de1c --- /dev/null +++ b/tests/smoke/pages/sound.html @@ -0,0 +1,29 @@ + + + +Sound idle + + +
CLICK FOR SOUND
+ + + diff --git a/tests/smoke/pages/tone.ogg b/tests/smoke/pages/tone.ogg new file mode 100644 index 0000000..cd0aa98 Binary files /dev/null and b/tests/smoke/pages/tone.ogg differ