S051: WIP tab audio from is-playing-audio, site mute through WebKit, media-audio smoke

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-14 08:07:37 -06:00
commit 28efd283e5
11 changed files with 74 additions and 12 deletions

View file

@ -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-<profile>/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.

View file

@ -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<u64> = 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),

View file

@ -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 {

View file

@ -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| {

View file

@ -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`).

View file

@ -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();

View file

@ -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})),

View file

@ -168,6 +168,8 @@ pub struct Tab {
pub status_text: Option<String>,
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<Url>,
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 {

View file

@ -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 <out>
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

View file

@ -0,0 +1,29 @@
<!doctype html>
<html>
<!-- Media on WebKit (S051): a quiet Web Audio tone after the first click (autoplay needs a gesture), so WebKit's
is-playing-audio turns on. With `?element` an <audio> element plays tone.ogg instead (Media Session metadata
set), which the page probe and WebKit's own MPRIS player see. -->
<head><meta charset="utf-8"><title>Sound idle</title>
<style>body { margin: 0; height: 100vh; background: #2d4a2d; color: #fff; font: bold 40px sans-serif; display: grid; place-items: center; }</style></head>
<body>
<div>CLICK FOR SOUND</div>
<script>
document.addEventListener('click', () => {
if (window.ctx || window.el) return;
if (location.search === '?element') {
window.el = new Audio('tone.ogg');
el.loop = true;
navigator.mediaSession.metadata = new MediaMetadata({ title: 'Smoke Tone', artist: 'Smoke Artist' });
el.play().then(() => document.title = 'Sound on');
return;
}
window.ctx = new AudioContext();
const osc = ctx.createOscillator(), gain = ctx.createGain();
gain.gain.value = 0.02;
osc.connect(gain).connect(ctx.destination);
osc.start();
document.title = 'Sound on';
});
</script>
</body>
</html>

BIN
tests/smoke/pages/tone.ogg Normal file

Binary file not shown.