Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cff5f49dc3 |
No files matched your search
+10
-13
@@ -6,16 +6,12 @@ on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
# Pure MoonBit: type-check every package and run the portable model tests
|
||||
# directly on the Depot Ubuntu 24.04 runner.
|
||||
# Pure MoonBit: type-check every package and run the model tests.
|
||||
# Needs no audio/GUI libraries, so it runs on the default runner image
|
||||
# (node:20-bullseye-like).
|
||||
check:
|
||||
runs-on: depot-ubuntu-24.04-4
|
||||
timeout-minutes: 15
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -30,18 +26,19 @@ jobs:
|
||||
moon check --target native --deny-warn
|
||||
moon fmt --check
|
||||
|
||||
# Native tests run in the trixie job: linking MoonBit's runtime needs
|
||||
# -lpthread on bullseye's glibc 2.31.
|
||||
- name: moon test (pure packages)
|
||||
run: moon test --target wasm-gc
|
||||
|
||||
# Native build + headless smoke test. Ubuntu 24.04 (the Depot host image)
|
||||
# only ships WirePlumber 0.4, so this job runs in a debian:trixie container
|
||||
# (PipeWire 1.4, WirePlumber 0.5, GTK 4.18).
|
||||
# Native build + headless smoke test. Debian bullseye (the default runner
|
||||
# image) has no libwireplumber-0.5 and a too-old GTK4, so this job runs in
|
||||
# a debian:trixie container (PipeWire 1.4, WirePlumber 0.5, GTK 4.18).
|
||||
# The container has no Node, so actions/checkout cannot run; clone with git.
|
||||
native:
|
||||
runs-on: depot-ubuntu-24.04-4
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: debian:trixie
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Install build and test dependencies
|
||||
run: |
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
type: feature
|
||||
---
|
||||
|
||||
Name Chrome's audio streams after their browser tabs, one row per tab, with an optional browser extension and native-messaging host; without it, a browser's only running stream shows its MPRIS title.
|
||||
@@ -19,7 +19,6 @@ COPY cmd/ cmd/
|
||||
COPY model/ model/
|
||||
COPY wp/ wp/
|
||||
COPY gtk/ gtk/
|
||||
COPY tabs/ tabs/
|
||||
COPY tools/pkg-cc tools/pkg-ar tools/
|
||||
RUN moon build --target native --release \
|
||||
&& install -Dm755 _build/native/release/build/cmd/moonmix/moonmix.exe /out/usr/local/bin/moonmix \
|
||||
|
||||
@@ -25,8 +25,6 @@ on top of libpipewire-0.3. It never runs `wpctl`, `pactl`, `pw-cli`,
|
||||
|
||||
- **Playback**: every application stream, with a volume slider, mute and the
|
||||
output device it plays to (choose another to move it).
|
||||
- **Browser tabs**: with the [browser extension](#browser-tabs), Chrome's
|
||||
streams are named after their tabs, one row per tab.
|
||||
- **Recording**: capture streams, same controls, input device selector.
|
||||
- **Output Devices** / **Input Devices**: sinks and sources with volume, mute
|
||||
and a *Default* toggle that shows and sets the default device.
|
||||
@@ -57,9 +55,6 @@ sliders, monitor sources in Input Devices, meters for recording streams.
|
||||
```
|
||||
cmd/moonmix GUI: builds tabs, reconciles widgets with view rows
|
||||
cmd/moonmix-probe headless CLI over the same stack (smoke tests, debugging)
|
||||
cmd/moonmix-tabs-host native-messaging host: names browser streams by tab
|
||||
extension/ the browser extension it talks to
|
||||
tabs/ tab name files and MPRIS: tabs_stub.c + tabs.mbt
|
||||
model/ pure MoonBit: volume curve, state reducer, view model
|
||||
wp/ WirePlumber binding: wp_stub.c + wp.mbt
|
||||
gtk/ minimal hand-written GTK4 binding: gtk_stub.c + gtk.mbt
|
||||
@@ -108,45 +103,6 @@ flowchart LR
|
||||
scroll handling (10% per detent, swallowing every scroll) with one that
|
||||
asks MoonBit synchronously whether the slider or the list gets the event.
|
||||
|
||||
## Browser tabs
|
||||
|
||||
Chrome opens separate audio streams for each tab (one for the media elements
|
||||
of the page and its frames, others for Web Audio), so each tab already has its
|
||||
own volume, mute, output and meter. But every stream is called "Google
|
||||
Chrome / Playback". To name them:
|
||||
|
||||
```sh
|
||||
just install-browser-tabs
|
||||
```
|
||||
|
||||
then open `chrome://extensions`, turn on *Developer mode*, choose *Load
|
||||
unpacked* and select `~/.local/share/moonmix/extension`. This works for
|
||||
Chrome, Chromium, Brave, Edge and Vivaldi installed natively (a Flatpak or
|
||||
Snap browser cannot start the host). `tools/install-browser-tabs.py
|
||||
--uninstall` removes it again.
|
||||
|
||||
- The **extension** tells **moonmix-tabs-host** (native messaging, started by
|
||||
the browser) which tabs are audible, with their titles. It sends no page
|
||||
addresses and nothing about silent or incognito tabs, and nothing leaves
|
||||
the machine. Its `tabs` permission does allow it to see titles and
|
||||
addresses of all tabs.
|
||||
- The browser does not say which stream is which tab's. The host sees streams
|
||||
start and tabs become audible, and **matches them by time**
|
||||
(`model/tabs.mbt`), or by elimination when only one tab can be meant. It
|
||||
runs as long as the browser, so the mixer need not be open. It publishes
|
||||
the matches in `$XDG_RUNTIME_DIR/moonmix/` (mode 0700).
|
||||
- **Ambiguous streams keep the browser's name**: tabs that start within the
|
||||
same moment, or several that were already playing when the host started.
|
||||
Pausing one and playing it again resolves it.
|
||||
- Streams of one tab share a row, which controls all of them.
|
||||
|
||||
Without the extension, a browser's only running stream shows the title the
|
||||
browser publishes over **MPRIS**. WirePlumber remembers volumes per
|
||||
application, so a new tab starts at the volume last set for any tab.
|
||||
|
||||
The container image only reads the published names: the host and extension
|
||||
are installed natively.
|
||||
|
||||
## Appearance
|
||||
|
||||
moonmix reads the desktop's **accent colour** and **colour scheme** from the
|
||||
@@ -231,9 +187,8 @@ install -Dm644 -t ~/.local/share/icons/hicolor/scalable/actions data/icons/hicol
|
||||
gtk-update-icon-cache -f -t ~/.local/share/icons/hicolor # optional
|
||||
```
|
||||
|
||||
The app icon is `org.latha.moonmix` (a dark-slate 2.5D mixer deck with a
|
||||
crescent moon and stereo peak LEDs above three sky-blue faders), shipped as
|
||||
scalable and symbolic SVGs under
|
||||
The app icon is `org.latha.moonmix` (three gold-lit mixer faders on a dark
|
||||
violet-slate card), shipped as scalable and symbolic SVGs under
|
||||
`data/icons/hicolor/`. The window uses it as its icon and the program name is
|
||||
`org.latha.moonmix`, which matches the `.desktop` file so Wayland shells show
|
||||
it too. Run from a checkout, moonmix also searches `./data/icons` and
|
||||
@@ -267,8 +222,7 @@ set `MOONMIX_IMAGE` to run a different local tag.
|
||||
|
||||
The runner maps your user ID and mounts only the Wayland and PipeWire
|
||||
sockets (including `PIPEWIRE_RUNTIME_DIR` / `PIPEWIRE_REMOTE` overrides),
|
||||
`$XDG_RUNTIME_DIR/bus` when present for desktop appearance settings,
|
||||
`$XDG_RUNTIME_DIR/moonmix` (browser tab names) read-only, and
|
||||
`$XDG_RUNTIME_DIR/bus` when present for desktop appearance settings, and
|
||||
whichever standard host icon, pixmap and `.desktop` directories exist
|
||||
(`/usr/share/{icons,pixmaps,applications}`, Flatpak exports and
|
||||
`$XDG_DATA_HOME/{icons,applications}`) read-only under `/run/moonmix/host/`.
|
||||
@@ -353,8 +307,7 @@ tools/smoke-test.sh /tmp/shot # needs pipewire, wireplumber, pw-cat, gtk4-
|
||||
`XDG_RUNTIME_DIR`. The instance has two null sinks, a loopback virtual
|
||||
microphone, one playback stream of noise and one capture stream created with `pw-cat`; the CLI is used only
|
||||
by the test harness. The script runs every probe action and checks its effect, checks that peak
|
||||
meters on the stream and its sink see the signal, checks tab naming with a
|
||||
fake browser (`tools/fake-browser.py`),
|
||||
meters on the stream and its sink see the signal,
|
||||
then starts the GUI under GTK's broadway backend. With `MOONMIX_SCREENSHOT`
|
||||
set, the GUI renders each tab offscreen to a PNG and exits. If `python3`
|
||||
with PyGObject and `dbus-daemon` are available, it then starts a private
|
||||
@@ -362,10 +315,9 @@ session bus with a fake portal (`tools/fake-portal.py`) that reports a green
|
||||
accent, switches it to orange while moonmix runs, and renders the tabs again
|
||||
(`<prefix>-accent-<n>.png`) once the change has been applied.
|
||||
|
||||
CI (`.gitea/workflows/ci.yaml`) runs on Depot (`depot-ubuntu-24.04-4`) runners:
|
||||
pure checks run directly on Ubuntu 24.04, and the native build and smoke test
|
||||
run in a `debian:trixie` container because Ubuntu 24.04 only ships WirePlumber
|
||||
0.4.
|
||||
CI (`.gitea/workflows/ci.yaml`) runs the pure checks on the default runner.
|
||||
It runs the native build and the smoke test in a `debian:trixie` container,
|
||||
because bullseye has no WirePlumber 0.5.
|
||||
|
||||
## Releases
|
||||
|
||||
|
||||
@@ -35,9 +35,6 @@ fn print_state(state : @model.State) -> Unit {
|
||||
flags.push("-> " + r.choices[r.current_choice].label)
|
||||
}
|
||||
let vol = if r.has_volume { r.volume_text } else { "(no volume)" }
|
||||
if r.members.length() > 1 {
|
||||
flags.push("\{r.members.length()} streams")
|
||||
}
|
||||
let f = if flags.length() > 0 {
|
||||
" [" + flags.join(", ") + "]"
|
||||
} else {
|
||||
@@ -113,8 +110,6 @@ fn main {
|
||||
// default-nodes-api reports defaults shortly after Ready: settle first.
|
||||
Ready => @wp.timeout(300, 2)
|
||||
Timeout(2) => {
|
||||
let names = @model.merge_tab_files(@tabs.files())
|
||||
let _ = state.apply(TabNames(names))
|
||||
print_state(state)
|
||||
if args is ["meter", id] {
|
||||
let id = resolve(state, id)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Headless probe: prints what each tab shows, can apply one action.
|
||||
import {
|
||||
"geordi/moonmix/model",
|
||||
"geordi/moonmix/tabs",
|
||||
"geordi/moonmix/wp",
|
||||
"moonbitlang/core/env",
|
||||
"moonbitlang/core/string",
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
// moonmix-tabs-host: started by the browser for the moonmix extension
|
||||
// (native messaging). It sees tabs become audible and the browser's PipeWire
|
||||
// streams start, matches the two (@model.TabTracker) and publishes the
|
||||
// result for the mixer. It runs as long as the browser, so streams that
|
||||
// started before the mixer was opened have names too.
|
||||
//
|
||||
// stdout belongs to the native-messaging protocol: never print.
|
||||
|
||||
///|
|
||||
extern "C" fn c_exit(code : Int32) = "exit"
|
||||
|
||||
///|
|
||||
const TICK_MS : Int32 = 500
|
||||
|
||||
///|
|
||||
struct Host {
|
||||
browser : Int32
|
||||
state : @model.State
|
||||
tracker : @model.TabTracker
|
||||
mut ready : Bool
|
||||
mut published : @model.TabFile?
|
||||
}
|
||||
|
||||
///|
|
||||
fn Host::stop(_ : Host) -> Unit {
|
||||
@tabs.unpublish()
|
||||
c_exit(0)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Serials of the browser's running playback streams. Its audio service,
|
||||
/// which owns them, is a child of the browser process.
|
||||
fn Host::running(self : Host) -> Array[String] {
|
||||
let out = []
|
||||
for _, n in self.state.nodes {
|
||||
if n.kind() is PlaybackStream &&
|
||||
n.running &&
|
||||
n.parent_pid == self.browser &&
|
||||
n.serial != "" {
|
||||
out.push(n.serial)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
fn Host::update(self : Host) -> Unit {
|
||||
if !self.ready {
|
||||
return
|
||||
}
|
||||
let now = @tabs.now_ms()
|
||||
// Another profile of this browser runs its own host with its own tabs.
|
||||
let others = @tabs.files().filter(fn(f) { f.browser == self.browser })
|
||||
self.tracker.settle(now, eliminate=others.length() <= 1)
|
||||
let file : @model.TabFile = {
|
||||
browser: self.browser,
|
||||
streams: self.tracker.matches(),
|
||||
}
|
||||
if self.published != Some(file) && @tabs.publish(file) {
|
||||
self.published = Some(file)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn main {
|
||||
let host : Host = {
|
||||
browser: @tabs.browser_pid(),
|
||||
state: @model.State::new(),
|
||||
tracker: @model.TabTracker::new(),
|
||||
ready: false,
|
||||
published: None,
|
||||
}
|
||||
@tabs.prune()
|
||||
@tabs.on_event(fn(ev) {
|
||||
match ev {
|
||||
Message =>
|
||||
match @model.parse_tabs(@tabs.message()) {
|
||||
Some(tabs) => {
|
||||
host.tracker.set_tabs(tabs, @tabs.now_ms())
|
||||
host.update()
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
Eof => host.stop()
|
||||
_ => ()
|
||||
}
|
||||
})
|
||||
@wp.on_event(fn(ev) {
|
||||
for e in @wp.to_model_events(ev) {
|
||||
let _ = host.state.apply(e)
|
||||
}
|
||||
match ev {
|
||||
Ready => {
|
||||
host.ready = true
|
||||
host.tracker.set_streams(host.running(), @tabs.now_ms(), initial=true)
|
||||
host.update()
|
||||
@wp.timeout(TICK_MS, 1)
|
||||
}
|
||||
Timeout(1) => {
|
||||
host.update()
|
||||
@wp.timeout(TICK_MS, 1)
|
||||
}
|
||||
// The extension starts a new host, which reconnects.
|
||||
Disconnected | PluginError => host.stop()
|
||||
NodeAdded(_) | NodeChanged(_) | NodeRemoved(_) =>
|
||||
if host.ready {
|
||||
host.tracker.set_streams(host.running(), @tabs.now_ms())
|
||||
host.update()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
})
|
||||
if !@wp.start() {
|
||||
c_exit(1)
|
||||
}
|
||||
@tabs.listen()
|
||||
@wp.run()
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Native-messaging host: matches browser tabs to PipeWire streams.
|
||||
import {
|
||||
"geordi/moonmix/model",
|
||||
"geordi/moonmix/tabs",
|
||||
"geordi/moonmix/wp",
|
||||
}
|
||||
|
||||
supported_targets = "-all+native"
|
||||
|
||||
pkgtype(kind: "executable")
|
||||
|
||||
options(
|
||||
link: { "native": { "cc": "tools/pkg-cc" } },
|
||||
)
|
||||
@@ -1,13 +0,0 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "geordi/moonmix/cmd/moonmix-tabs-host"
|
||||
|
||||
// Values
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
type Host
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
+5
-63
@@ -152,9 +152,7 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
||||
match app.find_view(tab, id) {
|
||||
Some(v) =>
|
||||
if idx >= 0 && idx < v.row.choices.length() {
|
||||
for m in v.row.members {
|
||||
let _ = @wp.move_stream(m, v.row.choices[idx].id)
|
||||
}
|
||||
let _ = @wp.move_stream(id, v.row.choices[idx].id)
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -201,11 +199,7 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
||||
let (mute, mute_tag) = @gtk.toggle(
|
||||
@gtk.resolve_icon(@model.volume_icon_chain(row.percent, row.mute)),
|
||||
"",
|
||||
fn(on) {
|
||||
for m in app.members(tab, id) {
|
||||
let _ = @wp.set_mute(m, on)
|
||||
}
|
||||
},
|
||||
fn(on) { let _ = @wp.set_mute(id, on) },
|
||||
)
|
||||
tags.push(mute_tag)
|
||||
mute.set_tooltip("Mute")
|
||||
@@ -226,14 +220,6 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
||||
v.last_local_us = @gtk.now_us()
|
||||
v.volume_label.set_text(@model.format_volume(vols))
|
||||
let _ = @wp.set_volumes(id, vols)
|
||||
for m in v.row.members {
|
||||
match app.state.nodes.get(m) {
|
||||
Some(n) if m != id =>
|
||||
@wp.set_volumes(m, @model.scale_linked(n.volumes, percent))
|
||||
|> ignore
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -353,15 +339,6 @@ fn App::find_view(self : App, tab : @model.Tab, id : Int32) -> RowView? {
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
/// Nodes a row controls.
|
||||
fn App::members(self : App, tab : @model.Tab, id : Int32) -> Array[Int32] {
|
||||
match self.find_view(tab, id) {
|
||||
Some(v) => v.row.members
|
||||
None => [id]
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn App::sync_default_button(self : App, tab : @model.Tab, id : Int32) -> Unit {
|
||||
match self.find_view(tab, id) {
|
||||
@@ -434,9 +411,7 @@ fn App::sync_meters(self : App) -> Unit {
|
||||
Some(t) =>
|
||||
if t.tab.has_meter() {
|
||||
for row in t.rows {
|
||||
for m in row.members {
|
||||
want.set(m, t.tab.node_kind())
|
||||
}
|
||||
want.set(row.id, t.tab.node_kind())
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
@@ -475,16 +450,8 @@ fn App::tick_meters(self : App) -> Unit {
|
||||
}
|
||||
match self.tabs.get(self.current.val) {
|
||||
Some(t) =>
|
||||
for _, v in t.views {
|
||||
let mut loudest : Double? = None
|
||||
for m in v.row.members {
|
||||
match (@wp.meter_take(m), loudest) {
|
||||
(Some(p), Some(l)) => if p > l { loudest = Some(p) }
|
||||
(Some(p), None) => loudest = Some(p)
|
||||
(None, _) => ()
|
||||
}
|
||||
}
|
||||
match loudest {
|
||||
for id, v in t.views {
|
||||
match @wp.meter_take(id) {
|
||||
Some(peak) => {
|
||||
let next = @model.meter_step(
|
||||
v.shown_level,
|
||||
@@ -546,30 +513,6 @@ fn App::on_wp_event(self : App, ev : @wp.Event) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Follow browser tab names (moonmix-tabs-host) and MPRIS titles.
|
||||
fn App::follow_tabs(self : App) -> Unit {
|
||||
fn apply(ev : @model.Event) {
|
||||
if self.state.apply(ev) {
|
||||
self.render()
|
||||
}
|
||||
}
|
||||
|
||||
fn names() {
|
||||
apply(TabNames(@model.merge_tab_files(@tabs.files())))
|
||||
}
|
||||
|
||||
@tabs.on_event(fn(ev) {
|
||||
match ev {
|
||||
Files => names()
|
||||
Media => apply(MediaTitles(@tabs.media_titles()))
|
||||
_ => ()
|
||||
}
|
||||
})
|
||||
@tabs.watch()
|
||||
names()
|
||||
}
|
||||
|
||||
///|
|
||||
fn build_ui() -> App {
|
||||
@gtk.load_css(CSS)
|
||||
@@ -727,7 +670,6 @@ fn main {
|
||||
if !@wp.start() {
|
||||
app.set_status("Cannot connect to PipeWire. Is pipewire running?")
|
||||
}
|
||||
app.follow_tabs()
|
||||
app.window.present()
|
||||
app.start_meter_timer()
|
||||
if screenshot is Some(prefix) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// The GUI.
|
||||
import {
|
||||
"geordi/moonmix/model",
|
||||
"geordi/moonmix/tabs",
|
||||
"geordi/moonmix/wp",
|
||||
"geordi/moonmix/gtk",
|
||||
"moonbitlang/core/env",
|
||||
|
||||
@@ -1,122 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128">
|
||||
<defs>
|
||||
<linearGradient id="edge" x1="0" y1="0" x2="1" y2="0">
|
||||
<stop offset="0" stop-color="#2c3144"/>
|
||||
<stop offset="0.1" stop-color="#171a25"/>
|
||||
<stop offset="0.5" stop-color="#131620"/>
|
||||
<stop offset="0.9" stop-color="#171a25"/>
|
||||
<stop offset="1" stop-color="#2a2f42"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="face" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#414860"/>
|
||||
<stop offset="0.5" stop-color="#2d3244"/>
|
||||
<stop offset="1" stop-color="#222635"/>
|
||||
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#2a2d3a"/>
|
||||
<stop offset="0.55" stop-color="#1d202a"/>
|
||||
<stop offset="1" stop-color="#17191f"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="rim" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#ffffff" stop-opacity="0.34"/>
|
||||
<stop offset="0.24" stop-color="#ffffff" stop-opacity="0.03"/>
|
||||
<stop offset="0.88" stop-color="#000000" stop-opacity="0.08"/>
|
||||
<stop offset="1" stop-color="#000000" stop-opacity="0.32"/>
|
||||
<stop offset="0" stop-color="#ffffff" stop-opacity="0.18"/>
|
||||
<stop offset="0.38" stop-color="#ffffff" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="screen" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#090c14"/>
|
||||
<stop offset="1" stop-color="#131929"/>
|
||||
</linearGradient>
|
||||
<radialGradient id="moon-bloom" cx="50%" cy="50%" r="50%">
|
||||
<stop offset="0" stop-color="#f8d26a" stop-opacity="0.32"/>
|
||||
<stop offset="1" stop-color="#f8d26a" stop-opacity="0"/>
|
||||
<radialGradient id="glow" cx="50%" cy="54%" r="44%">
|
||||
<stop offset="0" stop-color="#f5b021" stop-opacity="0.09"/>
|
||||
<stop offset="1" stop-color="#f5b021" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<linearGradient id="moon" x1="0.1" y1="0" x2="0.9" y2="1">
|
||||
<stop offset="0" stop-color="#fff8dd"/>
|
||||
<stop offset="0.55" stop-color="#f9d267"/>
|
||||
<stop offset="1" stop-color="#df9a20"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="glass" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#ffffff" stop-opacity="0.11"/>
|
||||
<stop offset="0.55" stop-color="#ffffff" stop-opacity="0.02"/>
|
||||
<stop offset="1" stop-color="#ffffff" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="track" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#76d0ff"/>
|
||||
<stop offset="0.45" stop-color="#3c92f0"/>
|
||||
<stop offset="1" stop-color="#2668cc"/>
|
||||
<linearGradient id="gold" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#f9c94e"/>
|
||||
<stop offset="0.55" stop-color="#f5b021"/>
|
||||
<stop offset="1" stop-color="#db9512"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="cap" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#ffffff"/>
|
||||
<stop offset="0.18" stop-color="#eef2f8"/>
|
||||
<stop offset="0.46" stop-color="#cdd4e2"/>
|
||||
<stop offset="0.54" stop-color="#b7c0d2"/>
|
||||
<stop offset="0.86" stop-color="#e3e8f2"/>
|
||||
<stop offset="1" stop-color="#cbd2e0"/>
|
||||
<stop offset="1" stop-color="#d7dbe5"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- Extruded 2.5D mixer console chassis -->
|
||||
<rect x="14" y="20" width="100" height="98" rx="18" fill="url(#edge)"/>
|
||||
<rect x="14" y="10" width="100" height="100" rx="18" fill="url(#face)"/>
|
||||
<rect x="14.75" y="10.75" width="98.5" height="98.5" rx="17.25" fill="none" stroke="url(#rim)" stroke-width="1.5"/>
|
||||
|
||||
<!-- Recessed OLED display window -->
|
||||
<rect x="23" y="19.5" width="82" height="27" rx="8" fill="#06080f" opacity="0.55"/>
|
||||
<rect x="23.5" y="20" width="81" height="26" rx="7.5" fill="url(#screen)"/>
|
||||
<path d="M 31 46.4 L 97 46.4" stroke="#ffffff" stroke-opacity="0.16" stroke-width="1" stroke-linecap="round"/>
|
||||
|
||||
<!-- Backlit crescent moon -->
|
||||
<circle cx="38.5" cy="33" r="11" fill="url(#moon-bloom)"/>
|
||||
<path d="M 41.6 26.4 A 7.1 7.1 0 1 0 41.6 39.6 A 5.6 5.6 0 1 1 41.6 26.4 Z" fill="url(#moon)"/>
|
||||
|
||||
<!-- Stereo peak-meter LEDs -->
|
||||
<rect x="52" y="26.5" width="7.2" height="4.8" rx="1.5" fill="#34d399"/>
|
||||
<rect x="61.2" y="26.5" width="7.2" height="4.8" rx="1.5" fill="#34d399"/>
|
||||
<rect x="70.4" y="26.5" width="7.2" height="4.8" rx="1.5" fill="#38bdf8"/>
|
||||
<rect x="79.6" y="26.5" width="7.2" height="4.8" rx="1.5" fill="#f7be42"/>
|
||||
<rect x="88.8" y="26.5" width="7.2" height="4.8" rx="1.5" fill="#232b40"/>
|
||||
|
||||
<rect x="52" y="34.5" width="7.2" height="4.8" rx="1.5" fill="#34d399"/>
|
||||
<rect x="61.2" y="34.5" width="7.2" height="4.8" rx="1.5" fill="#34d399"/>
|
||||
<rect x="70.4" y="34.5" width="7.2" height="4.8" rx="1.5" fill="#38bdf8"/>
|
||||
<rect x="79.6" y="34.5" width="7.2" height="4.8" rx="1.5" fill="#232b40"/>
|
||||
<rect x="88.8" y="34.5" width="7.2" height="4.8" rx="1.5" fill="#232b40"/>
|
||||
|
||||
<!-- Subtle glass reflection -->
|
||||
<path d="M 31 20 H 97 A 7.5 7.5 0 0 1 104.5 27.5 V 30 L 68 20 Z" fill="url(#glass)"/>
|
||||
|
||||
<!-- Etched dB scale ticks -->
|
||||
<g stroke="#ffffff" stroke-opacity="0.17" stroke-width="1.2" stroke-linecap="round">
|
||||
<line x1="23.5" y1="61" x2="26.5" y2="61"/>
|
||||
<line x1="23.5" y1="76" x2="26.5" y2="76"/>
|
||||
<line x1="23.5" y1="91" x2="26.5" y2="91"/>
|
||||
<line x1="101.5" y1="61" x2="104.5" y2="61"/>
|
||||
<line x1="101.5" y1="76" x2="104.5" y2="76"/>
|
||||
<line x1="101.5" y1="91" x2="104.5" y2="91"/>
|
||||
</g>
|
||||
<!-- Squircle card -->
|
||||
<rect x="8" y="8" width="112" height="112" rx="26" fill="url(#bg)"/>
|
||||
<rect x="8" y="8" width="112" height="112" rx="26" fill="url(#glow)"/>
|
||||
<rect x="8.5" y="8.5" width="111" height="111" rx="25.5" fill="none" stroke="#3c4154" stroke-opacity="0.65" stroke-width="1"/>
|
||||
<rect x="9" y="9" width="110" height="110" rx="25" fill="none" stroke="url(#rim)" stroke-width="1.2"/>
|
||||
|
||||
<!-- Recessed fader troughs -->
|
||||
<rect x="33.5" y="53" width="7.5" height="48" rx="3.75" fill="#0b0e16" stroke="#ffffff" stroke-opacity="0.07" stroke-width="0.8"/>
|
||||
<rect x="60.25" y="53" width="7.5" height="48" rx="3.75" fill="#0b0e16" stroke="#ffffff" stroke-opacity="0.07" stroke-width="0.8"/>
|
||||
<rect x="87" y="53" width="7.5" height="48" rx="3.75" fill="#0b0e16" stroke="#ffffff" stroke-opacity="0.07" stroke-width="0.8"/>
|
||||
<rect x="33" y="30" width="10" height="68" rx="5" fill="#0e1015" stroke="#ffffff" stroke-opacity="0.06" stroke-width="1"/>
|
||||
<rect x="59" y="30" width="10" height="68" rx="5" fill="#0e1015" stroke="#ffffff" stroke-opacity="0.06" stroke-width="1"/>
|
||||
<rect x="85" y="30" width="10" height="68" rx="5" fill="#0e1015" stroke="#ffffff" stroke-opacity="0.06" stroke-width="1"/>
|
||||
|
||||
<!-- Illuminated sky-blue level fills -->
|
||||
<rect x="33.5" y="75" width="7.5" height="26" rx="3.75" fill="url(#track)"/>
|
||||
<rect x="60.25" y="64" width="7.5" height="37" rx="3.75" fill="url(#track)"/>
|
||||
<rect x="87" y="84" width="7.5" height="17" rx="3.75" fill="url(#track)"/>
|
||||
<!-- Warm gold active level fills -->
|
||||
<rect x="33" y="56" width="10" height="42" rx="5" fill="url(#gold)"/>
|
||||
<rect x="59" y="44" width="10" height="54" rx="5" fill="url(#gold)"/>
|
||||
<rect x="85" y="70" width="10" height="28" rx="5" fill="url(#gold)"/>
|
||||
|
||||
<!-- Left fader cap -->
|
||||
<rect x="26.25" y="71.8" width="22" height="13.5" rx="3.5" fill="#06080e" opacity="0.58"/>
|
||||
<rect x="26.25" y="69" width="22" height="13.5" rx="3.5" fill="url(#cap)"/>
|
||||
<rect x="29.25" y="74.8" width="16" height="1.6" rx="0.8" fill="#1d2233" opacity="0.72"/>
|
||||
<rect x="29.25" y="76.4" width="16" height="0.8" rx="0.4" fill="#ffffff" opacity="0.7"/>
|
||||
<!-- Left fader cap (cx=38, cy=56) -->
|
||||
<rect x="27" y="51" width="22" height="14" rx="7" fill="#07080b" opacity="0.55"/>
|
||||
<rect x="27" y="49" width="22" height="14" rx="7" fill="url(#cap)"/>
|
||||
<rect x="33" y="55" width="10" height="2" rx="1" fill="#232632" opacity="0.26"/>
|
||||
|
||||
<!-- Center fader cap -->
|
||||
<rect x="53" y="60.8" width="22" height="13.5" rx="3.5" fill="#06080e" opacity="0.58"/>
|
||||
<rect x="53" y="58" width="22" height="13.5" rx="3.5" fill="url(#cap)"/>
|
||||
<rect x="56" y="63.8" width="16" height="1.6" rx="0.8" fill="#1d2233" opacity="0.72"/>
|
||||
<rect x="56" y="65.4" width="16" height="0.8" rx="0.4" fill="#ffffff" opacity="0.7"/>
|
||||
<!-- Center fader cap (cx=64, cy=44) -->
|
||||
<rect x="53" y="39" width="22" height="14" rx="7" fill="#07080b" opacity="0.55"/>
|
||||
<rect x="53" y="37" width="22" height="14" rx="7" fill="url(#cap)"/>
|
||||
<rect x="59" y="43" width="10" height="2" rx="1" fill="#232632" opacity="0.26"/>
|
||||
|
||||
<!-- Right fader cap -->
|
||||
<rect x="79.75" y="80.8" width="22" height="13.5" rx="3.5" fill="#06080e" opacity="0.58"/>
|
||||
<rect x="79.75" y="78" width="22" height="13.5" rx="3.5" fill="url(#cap)"/>
|
||||
<rect x="82.75" y="83.8" width="16" height="1.6" rx="0.8" fill="#1d2233" opacity="0.72"/>
|
||||
<rect x="82.75" y="85.4" width="16" height="0.8" rx="0.4" fill="#ffffff" opacity="0.7"/>
|
||||
<!-- Right fader cap (cx=90, cy=70) -->
|
||||
<rect x="79" y="65" width="22" height="14" rx="7" fill="#07080b" opacity="0.55"/>
|
||||
<rect x="79" y="63" width="22" height="14" rx="7" fill="url(#cap)"/>
|
||||
<rect x="85" y="69" width="10" height="2" rx="1" fill="#232632" opacity="0.26"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 3.0 KiB |
@@ -1,17 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||
<!-- Console housing frame (pure filled path for clean GTK symbolic recolouring) -->
|
||||
<path fill="#2e3436" fill-rule="evenodd" d="M 3.75 0.55 H 12.25 A 3.2 3.2 0 0 1 15.45 3.75 V 12.25 A 3.2 3.2 0 0 1 12.25 15.45 H 3.75 A 3.2 3.2 0 0 1 0.55 12.25 V 3.75 A 3.2 3.2 0 0 1 3.75 0.55 Z M 3.75 1.95 A 1.8 1.8 0 0 0 1.95 3.75 V 12.25 A 1.8 1.8 0 0 0 3.75 14.05 H 12.25 A 1.8 1.8 0 0 0 14.05 12.25 V 3.75 A 1.8 1.8 0 0 0 12.25 1.95 Z"/>
|
||||
<!-- Crescent moon and stereo meter bars -->
|
||||
<path d="M 6.0 3.2 A 1.75 1.75 0 1 0 6.0 6.4 A 1.35 1.35 0 1 1 6.0 3.2 Z" fill="#2e3436"/>
|
||||
<rect x="7.8" y="3.5" width="4.5" height="1.1" rx="0.55" fill="#2e3436" opacity="0.65"/>
|
||||
<rect x="7.8" y="5.1" width="3.2" height="1.1" rx="0.55" fill="#2e3436" opacity="0.45"/>
|
||||
<!-- Three fader tracks -->
|
||||
<rect x="3.9" y="7.8" width="1.2" height="5" rx="0.6" fill="#2e3436" opacity="0.45"/>
|
||||
<rect x="7.4" y="7.8" width="1.2" height="5" rx="0.6" fill="#2e3436" opacity="0.45"/>
|
||||
<rect x="10.9" y="7.8" width="1.2" height="5" rx="0.6" fill="#2e3436" opacity="0.45"/>
|
||||
<!-- Staggered fader caps -->
|
||||
<rect x="3.0" y="9.4" width="3.0" height="1.8" rx="0.7" fill="#2e3436"/>
|
||||
<rect x="6.5" y="8.0" width="3.0" height="1.8" rx="0.7" fill="#2e3436"/>
|
||||
<rect x="10.0" y="10.6" width="3.0" height="1.8" rx="0.7" fill="#2e3436"/>
|
||||
<!-- Upper inactive fader segments -->
|
||||
<rect x="2.1" y="2" width="1.8" height="4.5" rx="0.9" fill="#2e3436" opacity="0.45"/>
|
||||
<rect x="7.1" y="2" width="1.8" height="2.6" rx="0.9" fill="#2e3436" opacity="0.45"/>
|
||||
<rect x="12.1" y="2" width="1.8" height="7.5" rx="0.9" fill="#2e3436" opacity="0.45"/>
|
||||
<!-- Lower active fader segments -->
|
||||
<rect x="2.1" y="7.5" width="1.8" height="6.5" rx="0.9" fill="#2e3436"/>
|
||||
<rect x="7.1" y="5.5" width="1.8" height="8.5" rx="0.9" fill="#2e3436"/>
|
||||
<rect x="12.1" y="10.5" width="1.8" height="3.5" rx="0.9" fill="#2e3436"/>
|
||||
<!-- Pill knob caps at staggered heights (cy=7, 5, 10) -->
|
||||
<rect x="0.9" y="5.7" width="4.2" height="2.6" rx="1.3" fill="#2e3436"/>
|
||||
<rect x="5.9" y="3.7" width="4.2" height="2.6" rx="1.3" fill="#2e3436"/>
|
||||
<rect x="10.9" y="8.7" width="4.2" height="2.6" rx="1.3" fill="#2e3436"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 989 B |
@@ -1,68 +0,0 @@
|
||||
// Reports tabs that play audio to moonmix-tabs-host: id, title and whether
|
||||
// they are audible now. Tabs that never made a sound, page addresses and
|
||||
// incognito tabs are never sent.
|
||||
|
||||
const HOST = "org.latha.moonmix.tabs";
|
||||
const RETRY_MS = 5000;
|
||||
|
||||
// Tabs heard since the host connected. An open native port keeps this worker
|
||||
// alive, so nothing needs to be stored.
|
||||
const heard = new Map();
|
||||
let port = null;
|
||||
let retry = null;
|
||||
|
||||
function send() {
|
||||
port?.postMessage({ tabs: [...heard.values()] });
|
||||
}
|
||||
|
||||
// True if what we would send changed.
|
||||
function note(tab) {
|
||||
if (tab.id === undefined || tab.incognito) return false;
|
||||
const old = heard.get(tab.id);
|
||||
if (!old && !tab.audible) return false;
|
||||
const now = { id: tab.id, title: tab.title ?? "", audible: !!tab.audible };
|
||||
if (old && old.title === now.title && old.audible === now.audible) return false;
|
||||
heard.set(tab.id, now);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function connect() {
|
||||
if (port) return;
|
||||
clearTimeout(retry);
|
||||
const opened = chrome.runtime.connectNative(HOST);
|
||||
port = opened;
|
||||
opened.onDisconnect.addListener(() => {
|
||||
// Not installed, or PipeWire went away. lastError must be read.
|
||||
void chrome.runtime.lastError;
|
||||
if (port !== opened) return;
|
||||
port = null;
|
||||
retry = setTimeout(connect, RETRY_MS);
|
||||
});
|
||||
heard.clear();
|
||||
for (const tab of await chrome.tabs.query({ audible: true })) note(tab);
|
||||
send();
|
||||
}
|
||||
|
||||
chrome.tabs.onUpdated.addListener((_id, change, tab) => {
|
||||
if (!port) connect();
|
||||
else if (("audible" in change || "title" in change) && note(tab)) send();
|
||||
});
|
||||
|
||||
chrome.tabs.onRemoved.addListener((id) => {
|
||||
if (heard.delete(id)) send();
|
||||
});
|
||||
|
||||
// Prerendered or discarded tabs can come back with another id.
|
||||
chrome.tabs.onReplaced.addListener(async (added, removed) => {
|
||||
let changed = heard.delete(removed);
|
||||
try {
|
||||
changed = note(await chrome.tabs.get(added)) || changed;
|
||||
} catch {
|
||||
// Already closed.
|
||||
}
|
||||
if (changed) send();
|
||||
});
|
||||
|
||||
chrome.runtime.onStartup.addListener(connect);
|
||||
chrome.runtime.onInstalled.addListener(connect);
|
||||
connect();
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "moonmix tab names",
|
||||
"version": "0.1.0",
|
||||
"description": "Tells the moonmix volume control which tabs are playing audio.",
|
||||
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnwEsdryrEXsxfemPcrhQ0YTkIRqp0paRuD0RDKvQMWibZPHD7+Sx418+ytnaCAcS7AA0YNk97pq89PvmzWbsmXRFyDl0uAFLLsb/ibjdpr28rQ05Usb2Iu7/Lvaz5v7VEaF4qu8kcBhIzGJrheoxTnr0XUDn2/d+uJplpIKoDELgZ4c1qTrXz2kzyNuakr95JT35p/CJNY0vrd7LaauVsJnHwGgqB9FG91hJJgo6wZ27tObIS18yADa26looQJ5ObbXCLtOu6G7i8/ngxQhkfypRlDhKUj0xwYzak4iBMc9Qb1icSpNUjcS/NskUS0prhsQ2gZwPfGPjchaDX+C5WwIDAQAB",
|
||||
"minimum_chrome_version": "116",
|
||||
"permissions": ["tabs", "nativeMessaging"],
|
||||
"background": { "service_worker": "background.js" }
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Small-size version of data/icons/hicolor/scalable/apps/org.latha.moonmix.svg -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||||
<defs>
|
||||
<linearGradient id="face" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#414860"/>
|
||||
<stop offset="1" stop-color="#222635"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="moon" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#fff0b8"/>
|
||||
<stop offset="1" stop-color="#f2b53a"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- Chassis -->
|
||||
<rect x="1" y="3" width="30" height="28" rx="7" fill="#131620"/>
|
||||
<rect x="1" y="1" width="30" height="28" rx="7" fill="url(#face)"/>
|
||||
<rect x="1.5" y="1.5" width="29" height="27" rx="6.5" fill="none" stroke="#fff" stroke-opacity="0.16"/>
|
||||
|
||||
<!-- Display: crescent moon and level meter -->
|
||||
<rect x="4" y="4" width="24" height="10" rx="3" fill="#090c14"/>
|
||||
<path d="M 11 6 A 3.5 3.5 0 1 0 12 11.5 A 3.3 3.3 0 0 1 11 6 Z" fill="url(#moon)"/>
|
||||
<rect x="15" y="7" width="3" height="4" rx="1" fill="#34d399"/>
|
||||
<rect x="19" y="7" width="3" height="4" rx="1" fill="#38bdf8"/>
|
||||
<rect x="23" y="7" width="3" height="4" rx="1" fill="#f7be42"/>
|
||||
|
||||
<!-- Fader troughs and level fills -->
|
||||
<g fill="#0b0e16">
|
||||
<rect x="7" y="16" width="2" height="11" rx="1"/>
|
||||
<rect x="15" y="16" width="2" height="11" rx="1"/>
|
||||
<rect x="23" y="16" width="2" height="11" rx="1"/>
|
||||
</g>
|
||||
<g fill="#3c92f0">
|
||||
<rect x="7" y="22" width="2" height="5" rx="1"/>
|
||||
<rect x="15" y="18" width="2" height="9" rx="1"/>
|
||||
<rect x="23" y="24" width="2" height="3" rx="1"/>
|
||||
</g>
|
||||
|
||||
<!-- Fader caps -->
|
||||
<g fill="#eef2f8">
|
||||
<rect x="5" y="20" width="6" height="4" rx="1.25"/>
|
||||
<rect x="13" y="16" width="6" height="4" rx="1.25"/>
|
||||
<rect x="21" y="22" width="6" height="4" rx="1.25"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.8 KiB |
@@ -30,10 +30,6 @@ install: build
|
||||
update-desktop-database "$data_home/applications"
|
||||
fi
|
||||
|
||||
# Build and install the browser tab host and extension for your user.
|
||||
install-browser-tabs: build
|
||||
python3 tools/install-browser-tabs.py
|
||||
|
||||
# Type-check all native packages and check MoonBit formatting.
|
||||
check:
|
||||
moon check --target native
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Pure logic: volume curves, the audio-graph state reducer and the view
|
||||
// model the GUI renders. No FFI, so `moon test` runs it on any target.
|
||||
import {
|
||||
"moonbitlang/core/json",
|
||||
"moonbitlang/core/math",
|
||||
"moonbitlang/core/string",
|
||||
}
|
||||
@@ -24,12 +24,6 @@ pub const MIN_UI_CONTRAST : Double = 3.0
|
||||
|
||||
pub const NORM_PERCENT : Double = 100.0
|
||||
|
||||
pub const TAB_SETTLE_MS : Int64 = 3000
|
||||
|
||||
pub const TAB_SLOP_MS : Int64 = 400
|
||||
|
||||
pub const TAB_WINDOW_MS : Int64 = 1500
|
||||
|
||||
pub const WHEEL_STEP_PERCENT : Double = 2.0
|
||||
|
||||
pub fn accent_css(Rgb, Bool) -> String
|
||||
@@ -76,16 +70,10 @@ pub fn linear_to_percent(Double) -> Double
|
||||
|
||||
pub fn linked_percent(Array[Double]) -> Double
|
||||
|
||||
pub fn merge_tab_files(Array[TabFile]) -> Map[String, TabName]
|
||||
|
||||
pub fn meter_level(Double) -> Double
|
||||
|
||||
pub fn meter_step(Double, Double) -> Double
|
||||
|
||||
pub fn parse_media_titles(String) -> Map[Int32, String]
|
||||
|
||||
pub fn parse_tabs(String) -> Array[BrowserTab]?
|
||||
|
||||
pub fn percent_to_linear(Double) -> Double
|
||||
|
||||
pub fn readable_fg(Rgb) -> Rgb
|
||||
@@ -122,13 +110,6 @@ pub(all) struct AccentColors {
|
||||
}
|
||||
pub fn AccentColors::new(Rgb, Bool) -> Self
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct BrowserTab {
|
||||
id : Int32
|
||||
title : String
|
||||
audible : Bool
|
||||
}
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum ColorScheme {
|
||||
NoPreference
|
||||
@@ -157,8 +138,6 @@ pub(all) enum Event {
|
||||
Remove(Int32)
|
||||
Links(Array[Link])
|
||||
Defaults(sink~ : Int32, source~ : Int32)
|
||||
TabNames(Map[String, TabName])
|
||||
MediaTitles(Map[Int32, String])
|
||||
Reset
|
||||
}
|
||||
|
||||
@@ -181,14 +160,11 @@ pub(all) struct Node {
|
||||
bus : String
|
||||
app_binary : String
|
||||
app_id : String
|
||||
serial : String
|
||||
parent_pid : Int32
|
||||
running : Bool
|
||||
volumes : Array[Double]
|
||||
mute : Bool
|
||||
}
|
||||
pub fn Node::kind(Self) -> NodeKind
|
||||
pub fn Node::new(Int32, String, name? : String, description? : String, app_name? : String, media_name? : String, icon_hints? : Array[String], form_factor? : String, bus? : String, app_binary? : String, app_id? : String, serial? : String, parent_pid? : Int32, running? : Bool, volumes? : Array[Double], mute? : Bool) -> Self
|
||||
pub fn Node::new(Int32, String, name? : String, description? : String, app_name? : String, media_name? : String, icon_hints? : Array[String], form_factor? : String, bus? : String, app_binary? : String, app_id? : String, volumes? : Array[Double], mute? : Bool) -> Self
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum NodeKind {
|
||||
@@ -215,7 +191,6 @@ pub fn Rgb::to_hex(Self) -> String
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct Row {
|
||||
id : Int32
|
||||
members : Array[Int32]
|
||||
title : String
|
||||
subtitle : String
|
||||
icons : Array[String]
|
||||
@@ -249,15 +224,11 @@ pub(all) struct State {
|
||||
mut links : Array[Link]
|
||||
mut default_sink : Int32
|
||||
mut default_source : Int32
|
||||
mut tab_names : Map[String, TabName]
|
||||
mut media_titles : Map[Int32, String]
|
||||
}
|
||||
pub fn State::apply(Self, Event) -> Bool
|
||||
pub fn State::media_title(Self, Node) -> String?
|
||||
pub fn State::new() -> Self
|
||||
pub fn State::nodes_of(Self, NodeKind) -> Array[Node]
|
||||
pub fn State::stream_device(Self, Int32) -> Int32?
|
||||
pub fn State::tab_of(Self, Node) -> TabName?
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum Tab {
|
||||
@@ -273,35 +244,6 @@ pub fn Tab::icon_chain(Self) -> Array[String]
|
||||
pub fn Tab::label(Self) -> String
|
||||
pub fn Tab::node_kind(Self) -> NodeKind
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct TabFile {
|
||||
browser : Int32
|
||||
streams : Array[(String, Int32, String)]
|
||||
}
|
||||
pub fn TabFile::parse(String) -> Self?
|
||||
pub fn TabFile::to_text(Self) -> String
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct TabName {
|
||||
key : String
|
||||
title : String
|
||||
}
|
||||
|
||||
pub struct TabTracker {
|
||||
streams : Map[String, TrackedStream]
|
||||
tabs : Map[Int32, TrackedTab]
|
||||
mut got_tabs : Bool
|
||||
}
|
||||
pub fn TabTracker::matches(Self) -> Array[(String, Int32, String)]
|
||||
pub fn TabTracker::new() -> Self
|
||||
pub fn TabTracker::set_streams(Self, Array[String], Int64, initial? : Bool) -> Unit
|
||||
pub fn TabTracker::set_tabs(Self, Array[BrowserTab], Int64) -> Unit
|
||||
pub fn TabTracker::settle(Self, Int64, eliminate? : Bool) -> Unit
|
||||
|
||||
type TrackedStream
|
||||
|
||||
type TrackedTab
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum WheelRoute {
|
||||
Slider
|
||||
|
||||
+1
-61
@@ -40,9 +40,6 @@ pub(all) struct Node {
|
||||
bus : String // device.bus: "usb", "bluetooth", "pci", ...
|
||||
app_binary : String // application.process.binary
|
||||
app_id : String // pipewire.access.portal.app_id / application.id
|
||||
serial : String // object.serial, never reused (ids are)
|
||||
parent_pid : Int32 // parent of application.process.id; 0 if unknown
|
||||
running : Bool // streams: node state is "running"
|
||||
volumes : Array[Double] // linear, one per channel; empty = no volume
|
||||
mute : Bool
|
||||
}
|
||||
@@ -65,9 +62,6 @@ pub fn Node::new(
|
||||
bus~ : String = "",
|
||||
app_binary~ : String = "",
|
||||
app_id~ : String = "",
|
||||
serial~ : String = "",
|
||||
parent_pid~ : Int32 = 0,
|
||||
running~ : Bool = true,
|
||||
volumes~ : Array[Double] = [],
|
||||
mute~ : Bool = false,
|
||||
) -> Node {
|
||||
@@ -83,9 +77,6 @@ pub fn Node::new(
|
||||
bus,
|
||||
app_binary,
|
||||
app_id,
|
||||
serial,
|
||||
parent_pid,
|
||||
running,
|
||||
volumes,
|
||||
mute,
|
||||
}
|
||||
@@ -110,10 +101,6 @@ pub(all) enum Event {
|
||||
Links(Array[Link])
|
||||
/// Current default sink / source node ids (-1 = none).
|
||||
Defaults(sink~ : Int32, source~ : Int32)
|
||||
/// Streams matched to browser tabs, by object.serial.
|
||||
TabNames(Map[String, TabName])
|
||||
/// Title a browser is playing (MPRIS), by browser pid.
|
||||
MediaTitles(Map[Int32, String])
|
||||
/// Connection to PipeWire lost: forget everything.
|
||||
Reset
|
||||
}
|
||||
@@ -124,20 +111,11 @@ pub(all) struct State {
|
||||
mut links : Array[Link]
|
||||
mut default_sink : Int32
|
||||
mut default_source : Int32
|
||||
mut tab_names : Map[String, TabName]
|
||||
mut media_titles : Map[Int32, String]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn State::new() -> State {
|
||||
{
|
||||
nodes: {},
|
||||
links: [],
|
||||
default_sink: -1,
|
||||
default_source: -1,
|
||||
tab_names: Map([]),
|
||||
media_titles: Map([]),
|
||||
}
|
||||
{ nodes: {}, links: [], default_sink: -1, default_source: -1, }
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -174,16 +152,6 @@ pub fn State::apply(self : State, ev : Event) -> Bool {
|
||||
self.default_source = source
|
||||
changed
|
||||
}
|
||||
TabNames(names) => {
|
||||
let changed = names != self.tab_names
|
||||
self.tab_names = names
|
||||
changed
|
||||
}
|
||||
MediaTitles(titles) => {
|
||||
let changed = titles != self.media_titles
|
||||
self.media_titles = titles
|
||||
changed
|
||||
}
|
||||
Reset => {
|
||||
let changed = self.nodes.length() > 0 || self.links.length() > 0
|
||||
self.nodes.clear()
|
||||
@@ -258,34 +226,6 @@ pub fn display_title(n : Node) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// The browser tab a playback stream was matched to.
|
||||
pub fn State::tab_of(self : State, n : Node) -> TabName? {
|
||||
if n.kind() is PlaybackStream && n.serial != "" {
|
||||
self.tab_names.get(n.serial)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// What the stream's browser says it is playing (MPRIS): only when that can
|
||||
/// only mean this stream, i.e. it is the browser's one running stream.
|
||||
pub fn State::media_title(self : State, n : Node) -> String? {
|
||||
if !(n.kind() is PlaybackStream) || n.parent_pid == 0 || !n.running {
|
||||
return None
|
||||
}
|
||||
for _, other in self.nodes {
|
||||
if other.id != n.id &&
|
||||
other.kind() is PlaybackStream &&
|
||||
other.running &&
|
||||
other.parent_pid == n.parent_pid {
|
||||
return None
|
||||
}
|
||||
}
|
||||
self.media_titles.get(n.parent_pid)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Case-insensitive lexicographic comparison for display ordering.
|
||||
/// (MoonBit's built-in String compare orders by length first.)
|
||||
|
||||
-394
@@ -1,394 +0,0 @@
|
||||
// Which browser tab does a playback stream belong to?
|
||||
//
|
||||
// Chrome opens its audio streams per tab but gives them all the same
|
||||
// properties, and its extension API knows which tabs are audible but not
|
||||
// which stream they use. TabTracker links the two by time: a tab becomes
|
||||
// audible just after its stream starts running. Whatever stays ambiguous is
|
||||
// left unnamed; a wrong name is worse than none.
|
||||
|
||||
///|
|
||||
/// A tab reported by the browser extension.
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct BrowserTab {
|
||||
id : Int32
|
||||
title : String
|
||||
audible : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
/// A tab a stream was matched to, as the mixer shows it. `key` is unique
|
||||
/// across browsers; streams with the same key share one row.
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct TabName {
|
||||
key : String
|
||||
title : String
|
||||
}
|
||||
|
||||
///|
|
||||
/// A tab turns audible at most this long after its stream starts.
|
||||
pub const TAB_WINDOW_MS : Int64 = 1500L
|
||||
|
||||
///|
|
||||
/// ... and, since the two reports take different paths, at most this long
|
||||
/// before we see the stream.
|
||||
pub const TAB_SLOP_MS : Int64 = 400L
|
||||
|
||||
///|
|
||||
/// Streams older than this may be matched by elimination.
|
||||
pub const TAB_SETTLE_MS : Int64 = 3000L
|
||||
|
||||
///|
|
||||
struct TrackedStream {
|
||||
since : Int64
|
||||
/// False when it was already running when tracking began.
|
||||
seen_start : Bool
|
||||
mut tab : Int32?
|
||||
/// Matched by elimination, not by time.
|
||||
mut weak : Bool
|
||||
/// Elimination was contradicted: do not try it again.
|
||||
mut doubt : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
struct TrackedTab {
|
||||
mut title : String
|
||||
mut audible : Bool
|
||||
mut since : Int64
|
||||
mut seen_start : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub struct TabTracker {
|
||||
streams : Map[String, TrackedStream] // by object.serial
|
||||
tabs : Map[Int32, TrackedTab]
|
||||
mut got_tabs : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn TabTracker::new() -> TabTracker {
|
||||
{ streams: Map([]), tabs: Map([]), got_tabs: false, }
|
||||
}
|
||||
|
||||
///|
|
||||
/// The set of running streams. `initial` for the first, already running set.
|
||||
/// A stream that stops loses its tab: Chrome reuses idle streams.
|
||||
pub fn TabTracker::set_streams(
|
||||
self : TabTracker,
|
||||
serials : Array[String],
|
||||
now : Int64,
|
||||
initial~ : Bool = false,
|
||||
) -> Unit {
|
||||
for s in self.streams.keys().to_array() {
|
||||
if !serials.contains(s) {
|
||||
self.streams.remove(s)
|
||||
}
|
||||
}
|
||||
for s in serials {
|
||||
if !self.streams.contains(s) {
|
||||
self.streams.set(s, {
|
||||
since: now,
|
||||
seen_start: !initial,
|
||||
tab: None,
|
||||
weak: false,
|
||||
doubt: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// All tabs that are or have been audible and are still open.
|
||||
pub fn TabTracker::set_tabs(
|
||||
self : TabTracker,
|
||||
tabs : Array[BrowserTab],
|
||||
now : Int64,
|
||||
) -> Unit {
|
||||
let initial = !self.got_tabs
|
||||
self.got_tabs = true
|
||||
for id in self.tabs.keys().to_array() {
|
||||
if !tabs.any(fn(t) { t.id == id }) {
|
||||
self.tabs.remove(id)
|
||||
for _, s in self.streams {
|
||||
if s.tab == Some(id) {
|
||||
s.tab = None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for t in tabs {
|
||||
match self.tabs.get(t.id) {
|
||||
Some(old) => {
|
||||
old.title = t.title
|
||||
if t.audible && !old.audible {
|
||||
old.since = now
|
||||
old.seen_start = true
|
||||
}
|
||||
old.audible = t.audible
|
||||
}
|
||||
None =>
|
||||
self.tabs.set(t.id, {
|
||||
title: t.title,
|
||||
audible: t.audible,
|
||||
since: now,
|
||||
seen_start: !initial,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn TabTracker::has_stream(self : TabTracker, tab : Int32) -> Bool {
|
||||
for _, s in self.streams {
|
||||
if s.tab == Some(tab) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
///|
|
||||
fn in_window(s : TrackedStream, t : TrackedTab) -> Bool {
|
||||
let d = t.since - s.since
|
||||
s.seen_start && t.seen_start && d >= -TAB_SLOP_MS && d <= TAB_WINDOW_MS
|
||||
}
|
||||
|
||||
///|
|
||||
/// Match what can be matched at `now`. `eliminate` must be false when tabs
|
||||
/// of the same browser may be missing (another profile has its own list).
|
||||
pub fn TabTracker::settle(
|
||||
self : TabTracker,
|
||||
now : Int64,
|
||||
eliminate~ : Bool = true,
|
||||
) -> Unit {
|
||||
if !self.got_tabs {
|
||||
return
|
||||
}
|
||||
if !eliminate {
|
||||
for _, s in self.streams {
|
||||
if s.weak {
|
||||
s.tab = None
|
||||
s.weak = false
|
||||
}
|
||||
}
|
||||
}
|
||||
let audible : Array[Int32] = []
|
||||
let free_tabs : Array[Int32] = []
|
||||
for id, t in self.tabs {
|
||||
if t.audible {
|
||||
audible.push(id)
|
||||
if !self.has_stream(id) {
|
||||
free_tabs.push(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
// By time: the stream's only candidate is this tab. Several streams may
|
||||
// start with one tab (media plus Web Audio), never the reverse.
|
||||
let found : Array[(TrackedStream, Int32)] = []
|
||||
for _, s in self.streams {
|
||||
if s.tab is None && now - s.since >= TAB_WINDOW_MS {
|
||||
let near = audible.filter(fn(id) {
|
||||
match self.tabs.get(id) {
|
||||
Some(t) => in_window(s, t)
|
||||
None => false
|
||||
}
|
||||
})
|
||||
// A tab that already has a stream comes second.
|
||||
let free = near.filter(fn(id) { free_tabs.contains(id) })
|
||||
let cands = if free.length() > 0 { free } else { near }
|
||||
if cands is [id] {
|
||||
found.push((s, id))
|
||||
}
|
||||
}
|
||||
}
|
||||
for f in found {
|
||||
f.0.tab = Some(f.1)
|
||||
f.0.weak = false
|
||||
}
|
||||
// A tab has been audible for a while with no stream left for it: one of
|
||||
// the eliminated matches must be wrong, so drop them all.
|
||||
let left = free_tabs.filter(fn(id) { !self.has_stream(id) })
|
||||
let free_streams : Array[TrackedStream] = []
|
||||
let mut pending = false
|
||||
for _, s in self.streams {
|
||||
if s.tab is None {
|
||||
free_streams.push(s)
|
||||
if now - s.since < TAB_SETTLE_MS {
|
||||
pending = true
|
||||
}
|
||||
}
|
||||
}
|
||||
let overdue = left.any(fn(id) {
|
||||
match self.tabs.get(id) {
|
||||
Some(t) => now - t.since >= TAB_SETTLE_MS
|
||||
None => false
|
||||
}
|
||||
})
|
||||
if overdue && free_streams.length() == 0 {
|
||||
for _, s in self.streams {
|
||||
if s.weak {
|
||||
s.tab = None
|
||||
s.weak = false
|
||||
s.doubt = true
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if !eliminate || pending {
|
||||
return
|
||||
}
|
||||
let settled = left.all(fn(id) {
|
||||
match self.tabs.get(id) {
|
||||
Some(t) => now - t.since >= TAB_SETTLE_MS
|
||||
None => false
|
||||
}
|
||||
})
|
||||
if !settled {
|
||||
return
|
||||
}
|
||||
let target = if audible is [only] {
|
||||
// A single tab makes sound: every stream left is its own.
|
||||
Some(only)
|
||||
} else if left is [only] && free_streams.length() == 1 {
|
||||
Some(only)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
match target {
|
||||
Some(id) =>
|
||||
for s in free_streams {
|
||||
if !s.doubt {
|
||||
s.tab = Some(id)
|
||||
s.weak = true
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Matched streams: (object.serial, tab id, tab title).
|
||||
pub fn TabTracker::matches(self : TabTracker) -> Array[(String, Int32, String)] {
|
||||
let out = []
|
||||
for serial, s in self.streams {
|
||||
match s.tab {
|
||||
Some(id) =>
|
||||
match self.tabs.get(id) {
|
||||
Some(t) => out.push((serial, id, t.title))
|
||||
None => ()
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
/// Parse a message from the extension:
|
||||
/// `{"tabs":[{"id":1,"title":"...","audible":true}]}`. None if malformed.
|
||||
pub fn parse_tabs(text : String) -> Array[BrowserTab]? {
|
||||
let json = @json.parse(text) catch { _ => return None }
|
||||
guard json is Object({ "tabs": Array(items), .. }) else { return None }
|
||||
let out = []
|
||||
for item in items {
|
||||
guard item
|
||||
is Object(
|
||||
{
|
||||
"id": Number(id, ..),
|
||||
"title": String(title),
|
||||
"audible": True
|
||||
| False as audible,
|
||||
..
|
||||
}
|
||||
) else {
|
||||
return None
|
||||
}
|
||||
out.push({ id: id.to_int(), title, audible: audible is True, })
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
///|
|
||||
/// What one tab host publishes: its browser's pid and its matches.
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct TabFile {
|
||||
browser : Int32
|
||||
streams : Array[(String, Int32, String)] // serial, tab id, title
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn TabFile::to_text(self : TabFile) -> String {
|
||||
let streams : Array[Json] = self.streams.map(fn(s) {
|
||||
let o : Json = {
|
||||
"serial": Json::string(s.0),
|
||||
"tab": Json::number(s.1.to_double()),
|
||||
"title": Json::string(s.2),
|
||||
}
|
||||
o
|
||||
})
|
||||
let o : Json = {
|
||||
"browser": Json::number(self.browser.to_double()),
|
||||
"streams": Json::array(streams),
|
||||
}
|
||||
o.stringify()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn TabFile::parse(text : String) -> TabFile? {
|
||||
let json = @json.parse(text) catch { _ => return None }
|
||||
guard json
|
||||
is Object({ "browser": Number(pid, ..), "streams": Array(items), .. }) else {
|
||||
return None
|
||||
}
|
||||
let streams = []
|
||||
for item in items {
|
||||
guard item
|
||||
is Object(
|
||||
{
|
||||
"serial": String(serial),
|
||||
"tab": Number(tab, ..),
|
||||
"title": String(title),
|
||||
..
|
||||
}
|
||||
) else {
|
||||
return None
|
||||
}
|
||||
streams.push((serial, tab.to_int(), title))
|
||||
}
|
||||
Some({ browser: pid.to_int(), streams, })
|
||||
}
|
||||
|
||||
///|
|
||||
/// Names for the mixer from every host's file. A stream that two hosts
|
||||
/// claim (two profiles of one browser) is ambiguous and stays unnamed.
|
||||
pub fn merge_tab_files(files : Array[TabFile]) -> Map[String, TabName] {
|
||||
let out : Map[String, TabName] = Map([])
|
||||
let clash : Map[String, Bool] = Map([])
|
||||
for f in files {
|
||||
for s in f.streams {
|
||||
if out.contains(s.0) {
|
||||
clash.set(s.0, true)
|
||||
}
|
||||
out.set(s.0, { key: "\{f.browser}:\{s.1}", title: s.2, })
|
||||
}
|
||||
}
|
||||
for s, _ in clash {
|
||||
out.remove(s)
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
/// Parse "pid\ttitle" lines.
|
||||
pub fn parse_media_titles(text : String) -> Map[Int32, String] {
|
||||
let out : Map[Int32, String] = Map([])
|
||||
for line in text.split("\n") {
|
||||
match line.find("\t") {
|
||||
Some(i) => {
|
||||
let pid = @string.parse_int(line[:i]) catch { _ => continue }
|
||||
out.set(pid, line[i + 1:].to_owned())
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
///|
|
||||
fn tab(id : Int32, title : String, audible~ : Bool = true) -> @model.BrowserTab {
|
||||
{ id, title, audible, }
|
||||
}
|
||||
|
||||
///|
|
||||
/// Names by serial, sorted for comparison.
|
||||
fn names(t : @model.TabTracker) -> String {
|
||||
let out = t.matches().map(fn(m) { "\{m.0}=\{m.2}" })
|
||||
out.sort_by(@model.compare_text)
|
||||
out.join(" ")
|
||||
}
|
||||
|
||||
///|
|
||||
fn fresh() -> @model.TabTracker {
|
||||
let t = @model.TabTracker::new()
|
||||
t.set_streams([], 0L, initial=true)
|
||||
t.set_tabs([], 0L)
|
||||
t
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: matched by when they start, also long afterwards" {
|
||||
let t = fresh()
|
||||
t.set_streams(["1"], 1000L)
|
||||
t.set_tabs([tab(10, "A")], 1300L)
|
||||
t.settle(1500L)
|
||||
inspect(names(t), content="")
|
||||
t.set_streams(["1", "2"], 5000L)
|
||||
t.set_tabs([tab(10, "A"), tab(11, "B")], 5400L)
|
||||
t.settle(9000L)
|
||||
inspect(names(t), content="1=A 2=B")
|
||||
// A quiet passage and a new title do not lose the match.
|
||||
t.set_tabs([tab(10, "A2", audible=false), tab(11, "B")], 10000L)
|
||||
t.settle(20000L)
|
||||
inspect(names(t), content="1=A2 2=B")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: starting together is ambiguous" {
|
||||
let t = fresh()
|
||||
t.set_streams(["1", "2"], 1000L)
|
||||
t.set_tabs([tab(10, "A"), tab(11, "B")], 1300L)
|
||||
t.settle(20000L)
|
||||
inspect(names(t), content="")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: already playing at start" {
|
||||
let t = @model.TabTracker::new()
|
||||
t.set_streams(["1", "2"], 0L, initial=true)
|
||||
t.set_tabs([tab(10, "A"), tab(11, "B")], 0L)
|
||||
t.settle(20000L)
|
||||
inspect(names(t), content="")
|
||||
// With a single tab there is no doubt.
|
||||
let t = @model.TabTracker::new()
|
||||
t.set_streams(["1", "2"], 0L, initial=true)
|
||||
t.set_tabs([tab(10, "A")], 0L)
|
||||
t.settle(20000L)
|
||||
inspect(names(t), content="1=A 2=A")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: a second stream of the only tab joins it" {
|
||||
let t = fresh()
|
||||
t.set_streams(["1"], 1000L)
|
||||
t.set_tabs([tab(10, "A")], 1300L)
|
||||
t.settle(4000L)
|
||||
t.set_streams(["1", "2"], 5000L)
|
||||
t.settle(6000L)
|
||||
inspect(names(t), content="1=A")
|
||||
t.settle(9000L)
|
||||
inspect(names(t), content="1=A 2=A")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: media and Web Audio of one tab, next to another tab" {
|
||||
let t = fresh()
|
||||
t.set_streams(["1"], 1000L)
|
||||
t.set_tabs([tab(10, "A")], 1300L)
|
||||
t.settle(4000L)
|
||||
t.set_streams(["1", "2"], 9000L)
|
||||
t.set_streams(["1", "2", "3"], 9100L)
|
||||
t.set_tabs([tab(10, "A"), tab(11, "B")], 9300L)
|
||||
t.settle(10550L)
|
||||
t.settle(11000L)
|
||||
inspect(names(t), content="1=A 2=B 3=B")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: a contradicted elimination is dropped for good" {
|
||||
let t = fresh()
|
||||
t.set_streams(["1"], 1000L)
|
||||
t.set_tabs([tab(10, "A")], 1300L)
|
||||
t.settle(4000L)
|
||||
// Stream 2 is a silent tab's; B is heard only much later.
|
||||
t.set_streams(["1", "2"], 5000L)
|
||||
t.settle(9000L)
|
||||
inspect(names(t), content="1=A 2=A")
|
||||
t.set_tabs([tab(10, "A"), tab(11, "B")], 20000L)
|
||||
t.settle(24000L)
|
||||
inspect(names(t), content="1=A")
|
||||
t.settle(30000L)
|
||||
inspect(names(t), content="1=A")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: a stopped stream is forgotten, a closed tab too" {
|
||||
let t = fresh()
|
||||
t.set_streams(["1"], 1000L)
|
||||
t.set_tabs([tab(10, "A")], 1300L)
|
||||
t.settle(4000L)
|
||||
t.set_streams([], 5000L)
|
||||
inspect(names(t), content="")
|
||||
t.set_streams(["1"], 6000L)
|
||||
t.set_tabs([tab(11, "B")], 6300L)
|
||||
t.settle(9000L)
|
||||
inspect(names(t), content="1=B")
|
||||
t.set_tabs([], 10000L)
|
||||
inspect(names(t), content="")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: no elimination next to another profile" {
|
||||
let t = @model.TabTracker::new()
|
||||
t.set_streams(["1"], 0L, initial=true)
|
||||
t.set_tabs([tab(10, "A")], 0L)
|
||||
t.settle(9000L)
|
||||
inspect(names(t), content="1=A")
|
||||
t.settle(9500L, eliminate=false)
|
||||
inspect(names(t), content="")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: messages and files" {
|
||||
let parsed = @model.parse_tabs(
|
||||
"{\"tabs\":[{\"id\":7,\"title\":\"a \\\"b\\\" é\",\"audible\":true}]}",
|
||||
)
|
||||
assert_true(parsed == Some([tab(7, "a \"b\" é")]))
|
||||
assert_true(@model.parse_tabs("nope") is None)
|
||||
assert_true(@model.parse_tabs("{\"tabs\":[{\"id\":\"7\"}]}") is None)
|
||||
let file : @model.TabFile = {
|
||||
browser: 5,
|
||||
streams: [("84", 7, "x\n\"y\""), ("85", 8, "z")],
|
||||
}
|
||||
assert_true(@model.TabFile::parse(file.to_text()) == Some(file))
|
||||
assert_false(file.to_text().contains("\n"))
|
||||
assert_true(@model.TabFile::parse("{}") is None)
|
||||
let other : @model.TabFile = { browser: 5, streams: [("85", 9, "w")], }
|
||||
let merged = @model.merge_tab_files([file, other])
|
||||
inspect(merged.length(), content="1")
|
||||
inspect(merged.get("84").unwrap().key, content="5:7")
|
||||
let titles = @model.parse_media_titles("12\tSong\nbad\n")
|
||||
assert_true(titles.get(12) == Some("Song"))
|
||||
inspect(titles.length(), content="1")
|
||||
}
|
||||
|
||||
///|
|
||||
test "tabs: rows are named and grouped" {
|
||||
let s = @model.State::new()
|
||||
for id in [60, 61, 62] {
|
||||
let _ = s.apply(
|
||||
Upsert(
|
||||
@model.Node::new(
|
||||
id,
|
||||
"Stream/Output/Audio",
|
||||
app_name="Google Chrome",
|
||||
media_name="Playback",
|
||||
serial="\{id + 100}",
|
||||
parent_pid=5,
|
||||
volumes=[1.0],
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
let name : @model.TabName = { key: "5:1", title: "Music", }
|
||||
assert_true(s.apply(TabNames({ "160": name, "162": name })))
|
||||
assert_false(s.apply(TabNames({ "160": name, "162": name })))
|
||||
// Three running streams: a browser-wide title says nothing about one.
|
||||
let _ = s.apply(MediaTitles({ 5: "Song" }))
|
||||
let rows = @model.rows(s, Playback)
|
||||
inspect(
|
||||
rows
|
||||
.map(fn(r) { "\{r.title}/\{r.subtitle}/\{r.members.length()}" })
|
||||
.join(", "),
|
||||
content="Music/Google Chrome/2, Google Chrome/Playback/1",
|
||||
)
|
||||
let _ = s.apply(Remove(60))
|
||||
let _ = s.apply(Remove(62))
|
||||
inspect(@model.rows(s, Playback)[0].subtitle, content="Song")
|
||||
}
|
||||
+6
-37
@@ -58,9 +58,6 @@ pub(all) struct DeviceChoice {
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct Row {
|
||||
id : Int32
|
||||
/// Nodes this row controls: its own id first, then, for a browser tab, the
|
||||
/// tab's other streams.
|
||||
members : Array[Int32]
|
||||
title : String
|
||||
subtitle : String
|
||||
/// Icon-theme names to try in order (see icons.mbt).
|
||||
@@ -94,33 +91,12 @@ pub fn rows(state : State, tab : Tab) -> Array[Row] {
|
||||
.map(fn(d) { { id: d.id, name: d.name, label: display_title(d), } })
|
||||
None => []
|
||||
}
|
||||
// Streams of one browser tab share a row.
|
||||
let groups : Map[String, Array[Int32]] = Map([])
|
||||
let nodes = state
|
||||
.nodes_of(kind)
|
||||
.filter(fn(n) {
|
||||
match state.tab_of(n) {
|
||||
Some(t) =>
|
||||
match groups.get(t.key) {
|
||||
Some(g) => {
|
||||
g.push(n.id)
|
||||
false
|
||||
}
|
||||
None => {
|
||||
groups.set(t.key, [n.id])
|
||||
true
|
||||
}
|
||||
}
|
||||
None => true
|
||||
}
|
||||
})
|
||||
nodes.map(fn(n) {
|
||||
state
|
||||
.nodes_of(kind)
|
||||
.map(fn(n) {
|
||||
let is_stream = device_kind is Some(_)
|
||||
let tab = state.tab_of(n)
|
||||
let subtitle = if tab is Some(_) {
|
||||
display_title(n)
|
||||
} else if is_stream {
|
||||
state.media_title(n).unwrap_or(n.media_name)
|
||||
let subtitle = if is_stream {
|
||||
n.media_name
|
||||
} else if n.name != display_title(n) {
|
||||
n.name
|
||||
} else {
|
||||
@@ -149,14 +125,7 @@ pub fn rows(state : State, tab : Tab) -> Array[Row] {
|
||||
}
|
||||
{
|
||||
id: n.id,
|
||||
members: match tab {
|
||||
Some(t) => groups.get(t.key).unwrap_or([n.id])
|
||||
None => [n.id]
|
||||
},
|
||||
title: match tab {
|
||||
Some(t) if t.title != "" => t.title
|
||||
_ => display_title(n)
|
||||
},
|
||||
title: display_title(n),
|
||||
subtitle,
|
||||
icons: if is_stream {
|
||||
stream_icon_chain(n)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Browser tab names: native messaging (host side), the published files and
|
||||
// MPRIS titles (mixer side). Native only. See tabs_stub.c.
|
||||
import {
|
||||
"geordi/moonmix/model",
|
||||
"moonbitlang/core/encoding/utf8",
|
||||
}
|
||||
|
||||
supported_targets = "-all+native"
|
||||
|
||||
options(
|
||||
"native-stub": [ "tabs_stub.c" ],
|
||||
link: { "native": { "stub-cc": "tools/pkg-cc" } },
|
||||
)
|
||||
@@ -1,43 +0,0 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "geordi/moonmix/tabs"
|
||||
|
||||
import {
|
||||
"geordi/moonmix/model",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn browser_pid() -> Int32
|
||||
|
||||
pub fn files() -> Array[@model.TabFile]
|
||||
|
||||
pub fn listen() -> Unit
|
||||
|
||||
pub fn media_titles() -> Map[Int32, String]
|
||||
|
||||
pub fn message() -> String
|
||||
|
||||
pub fn now_ms() -> Int64
|
||||
|
||||
pub fn on_event((Event) -> Unit) -> Unit
|
||||
|
||||
pub fn prune() -> Unit
|
||||
|
||||
pub fn publish(@model.TabFile) -> Bool
|
||||
|
||||
pub fn unpublish() -> Unit
|
||||
|
||||
pub fn watch() -> Unit
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
pub(all) enum Event {
|
||||
Message
|
||||
Eof
|
||||
Files
|
||||
Media
|
||||
}
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
-134
@@ -1,134 +0,0 @@
|
||||
// MoonBit side of tabs_stub.c.
|
||||
|
||||
///|
|
||||
pub(all) enum Event {
|
||||
/// A native-messaging message arrived: `message`.
|
||||
Message
|
||||
/// The browser closed the connection, or asked us to stop.
|
||||
Eof
|
||||
/// The published files changed: `names`.
|
||||
Files
|
||||
/// What browsers play changed: `media_titles`.
|
||||
Media
|
||||
}
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_set_handler(
|
||||
call : FuncRef[((Int32) -> Unit, Int32) -> Unit],
|
||||
closure : (Int32) -> Unit,
|
||||
) = "mm_tabs_set_handler"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_now_ms() -> Int64 = "mm_tabs_now_ms"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_getppid() -> Int32 = "mm_tabs_getppid"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_listen() = "mm_tabs_listen"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_message() -> Bytes = "mm_tabs_message"
|
||||
|
||||
///|
|
||||
#borrow(text)
|
||||
extern "C" fn ffi_publish(text : Bytes) -> Int32 = "mm_tabs_publish"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_unpublish() = "mm_tabs_unpublish"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_prune() = "mm_tabs_prune"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_read() -> Bytes = "mm_tabs_read"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_watch() = "mm_tabs_watch"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_watch_media() = "mm_tabs_watch_media"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_media() -> Bytes = "mm_tabs_media"
|
||||
|
||||
///|
|
||||
/// Register the single event handler. Call before `listen` or `watch`.
|
||||
pub fn on_event(f : (Event) -> Unit) -> Unit {
|
||||
ffi_set_handler(fn(g, kind) { g(kind) }, fn(kind) {
|
||||
match kind {
|
||||
1 => f(Message)
|
||||
2 => f(Eof)
|
||||
3 => f(Files)
|
||||
4 => f(Media)
|
||||
_ => ()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn now_ms() -> Int64 {
|
||||
ffi_now_ms()
|
||||
}
|
||||
|
||||
///|
|
||||
/// The browser: it starts native-messaging hosts itself.
|
||||
pub fn browser_pid() -> Int32 {
|
||||
ffi_getppid()
|
||||
}
|
||||
|
||||
///|
|
||||
/// Read native messages from stdin.
|
||||
pub fn listen() -> Unit {
|
||||
ffi_listen()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn message() -> String {
|
||||
@utf8.decode_lossy(ffi_message())
|
||||
}
|
||||
|
||||
///|
|
||||
/// Publish this host's matches for running mixers.
|
||||
pub fn publish(file : @model.TabFile) -> Bool {
|
||||
let b = @utf8.encode(file.to_text())
|
||||
let n = b.length()
|
||||
ffi_publish(Bytes::makei(n + 1, fn(i) { if i < n { b[i] } else { b'\x00' } })) ==
|
||||
0
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn unpublish() -> Unit {
|
||||
ffi_unpublish()
|
||||
}
|
||||
|
||||
///|
|
||||
/// Remove files left by hosts that died.
|
||||
pub fn prune() -> Unit {
|
||||
ffi_prune()
|
||||
}
|
||||
|
||||
///|
|
||||
/// Everything published by hosts right now.
|
||||
pub fn files() -> Array[@model.TabFile] {
|
||||
let out = []
|
||||
for line in @utf8.decode_lossy(ffi_read()).split("\n") {
|
||||
match @model.TabFile::parse(line.to_owned()) {
|
||||
Some(f) => out.push(f)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
/// Report changes of the published files and of browsers' MPRIS titles.
|
||||
pub fn watch() -> Unit {
|
||||
ffi_watch()
|
||||
ffi_watch_media()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn media_titles() -> Map[Int32, String] {
|
||||
@model.parse_media_titles(@utf8.decode_lossy(ffi_media()))
|
||||
}
|
||||
@@ -1,336 +0,0 @@
|
||||
/*
|
||||
* moonmix: browser tab names.
|
||||
*
|
||||
* Host side: Chrome native messaging on stdin, and one published file per
|
||||
* host in $XDG_RUNTIME_DIR/moonmix (private, gone at logout).
|
||||
* Mixer side: watching that directory, and the titles Chromium-family
|
||||
* browsers publish over MPRIS.
|
||||
*
|
||||
* Everything runs on the GLib default main context (shared with WirePlumber
|
||||
* and GTK). MoonBit gets one callback with the kind of event.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib-unix.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include "moonbit.h"
|
||||
|
||||
enum {
|
||||
MM_TABS_MESSAGE = 1,
|
||||
MM_TABS_EOF = 2,
|
||||
MM_TABS_FILES = 3,
|
||||
MM_TABS_MEDIA = 4,
|
||||
};
|
||||
|
||||
/* Native messaging allows far more; a list of tabs never needs it. */
|
||||
#define MAX_MESSAGE (1024 * 1024)
|
||||
|
||||
typedef void (*mm_tcall_t)(void *closure, int32_t kind);
|
||||
static mm_tcall_t g_call;
|
||||
static void *g_closure;
|
||||
|
||||
static void emit(int32_t kind) {
|
||||
if (g_call) {
|
||||
moonbit_incref(g_closure);
|
||||
g_call(g_closure, kind);
|
||||
}
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_tabs_set_handler(mm_tcall_t call, void *closure) {
|
||||
if (g_closure)
|
||||
moonbit_decref(g_closure);
|
||||
g_call = call;
|
||||
g_closure = closure;
|
||||
}
|
||||
|
||||
static moonbit_bytes_t to_bytes(const char *s, size_t n) {
|
||||
moonbit_bytes_t b = moonbit_make_bytes((int32_t)n, 0);
|
||||
if (n)
|
||||
memcpy(b, s, n);
|
||||
return b;
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT int64_t mm_tabs_now_ms(void) {
|
||||
return g_get_monotonic_time() / 1000;
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT int32_t mm_tabs_getppid(void) { return getppid(); }
|
||||
|
||||
/* ---- native messaging --------------------------------------------------- */
|
||||
|
||||
static GByteArray *g_in;
|
||||
static GString *g_message;
|
||||
|
||||
static gboolean end_of_input(void) {
|
||||
emit(MM_TABS_EOF);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static gboolean on_stdin(gint fd, GIOCondition cond, gpointer d) {
|
||||
(void)cond;
|
||||
(void)d;
|
||||
guint8 buf[65536];
|
||||
ssize_t n = read(fd, buf, sizeof buf);
|
||||
if (n < 0 && (errno == EINTR || errno == EAGAIN))
|
||||
return G_SOURCE_CONTINUE;
|
||||
if (n <= 0)
|
||||
return end_of_input();
|
||||
g_byte_array_append(g_in, buf, (guint)n);
|
||||
while (g_in->len >= 4) {
|
||||
guint32 len; /* native byte order, per the protocol */
|
||||
memcpy(&len, g_in->data, 4);
|
||||
if (len > MAX_MESSAGE)
|
||||
return end_of_input();
|
||||
if (g_in->len < 4 + len)
|
||||
break;
|
||||
g_string_truncate(g_message, 0);
|
||||
g_string_append_len(g_message, (const char *)g_in->data + 4, len);
|
||||
g_byte_array_remove_range(g_in, 0, 4 + len);
|
||||
emit(MM_TABS_MESSAGE);
|
||||
}
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static gboolean on_term(gpointer d) {
|
||||
(void)d;
|
||||
return end_of_input();
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_tabs_listen(void) {
|
||||
g_in = g_byte_array_new();
|
||||
g_message = g_string_new(NULL);
|
||||
g_unix_fd_add(STDIN_FILENO, G_IO_IN | G_IO_HUP | G_IO_ERR, on_stdin, NULL);
|
||||
g_unix_signal_add(SIGTERM, on_term, NULL);
|
||||
g_unix_signal_add(SIGINT, on_term, NULL);
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT moonbit_bytes_t mm_tabs_message(void) {
|
||||
return to_bytes(g_message->str, g_message->len);
|
||||
}
|
||||
|
||||
/* ---- published files ---------------------------------------------------- */
|
||||
|
||||
static char *tabs_dir(void) {
|
||||
const char *dir = g_getenv("MOONMIX_TABS_DIR");
|
||||
if (dir && *dir)
|
||||
return g_strdup(dir);
|
||||
/* No fallback to a shared directory: titles are private. */
|
||||
dir = g_getenv("XDG_RUNTIME_DIR");
|
||||
return dir && *dir ? g_build_filename(dir, "moonmix", NULL) : NULL;
|
||||
}
|
||||
|
||||
static char *own_file(const char *dir) {
|
||||
char name[32];
|
||||
g_snprintf(name, sizeof name, "%d.json", (int)getpid());
|
||||
return g_build_filename(dir, name, NULL);
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT int32_t mm_tabs_publish(moonbit_bytes_t text) {
|
||||
g_autofree char *dir = tabs_dir();
|
||||
if (!dir || g_mkdir_with_parents(dir, 0700) != 0)
|
||||
return -1;
|
||||
g_autofree char *path = own_file(dir);
|
||||
return g_file_set_contents_full(path, (const char *)text, -1,
|
||||
G_FILE_SET_CONTENTS_CONSISTENT, 0600, NULL)
|
||||
? 0
|
||||
: -1;
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_tabs_unpublish(void) {
|
||||
g_autofree char *dir = tabs_dir();
|
||||
if (dir) {
|
||||
g_autofree char *path = own_file(dir);
|
||||
g_unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove files whose host was killed before it could. */
|
||||
MOONBIT_FFI_EXPORT void mm_tabs_prune(void) {
|
||||
g_autofree char *dir = tabs_dir();
|
||||
g_autoptr(GDir) d = dir ? g_dir_open(dir, 0, NULL) : NULL;
|
||||
const char *name;
|
||||
while (d && (name = g_dir_read_name(d))) {
|
||||
char *end;
|
||||
long pid = strtol(name, &end, 10);
|
||||
if (pid <= 0 || strcmp(end, ".json") != 0)
|
||||
continue;
|
||||
g_autofree char *proc = g_strdup_printf("/proc/%ld", pid);
|
||||
if (!g_file_test(proc, G_FILE_TEST_EXISTS)) {
|
||||
g_autofree char *path = g_build_filename(dir, name, NULL);
|
||||
g_unlink(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Every published file (each is one line of JSON), newline separated. */
|
||||
MOONBIT_FFI_EXPORT moonbit_bytes_t mm_tabs_read(void) {
|
||||
g_autofree char *dir = tabs_dir();
|
||||
g_autoptr(GDir) d = dir ? g_dir_open(dir, 0, NULL) : NULL;
|
||||
g_autoptr(GString) out = g_string_new(NULL);
|
||||
const char *name;
|
||||
while (d && (name = g_dir_read_name(d))) {
|
||||
if (!g_str_has_suffix(name, ".json"))
|
||||
continue;
|
||||
g_autofree char *path = g_build_filename(dir, name, NULL);
|
||||
g_autofree char *text = NULL;
|
||||
gsize len;
|
||||
if (g_file_get_contents(path, &text, &len, NULL) && len <= MAX_MESSAGE) {
|
||||
g_string_append_len(out, text, (gssize)len);
|
||||
g_string_append_c(out, '\n');
|
||||
}
|
||||
}
|
||||
return to_bytes(out->str, out->len);
|
||||
}
|
||||
|
||||
static void on_dir_changed(GFileMonitor *m, GFile *f, GFile *other,
|
||||
GFileMonitorEvent ev, gpointer d) {
|
||||
(void)m; (void)f; (void)other; (void)ev; (void)d;
|
||||
emit(MM_TABS_FILES);
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_tabs_watch(void) {
|
||||
static GFileMonitor *monitor;
|
||||
g_autofree char *dir = tabs_dir();
|
||||
if (monitor || !dir)
|
||||
return;
|
||||
/* May fail on the container's read-only mount, where it already exists. */
|
||||
g_mkdir_with_parents(dir, 0700);
|
||||
g_autoptr(GFile) file = g_file_new_for_path(dir);
|
||||
monitor = g_file_monitor_directory(file, G_FILE_MONITOR_WATCH_MOVES, NULL,
|
||||
NULL);
|
||||
if (monitor)
|
||||
g_signal_connect(monitor, "changed", G_CALLBACK(on_dir_changed), NULL);
|
||||
}
|
||||
|
||||
/* ---- MPRIS -------------------------------------------------------------- */
|
||||
|
||||
#define MPRIS "org.mpris.MediaPlayer2"
|
||||
#define MPRIS_CHROMIUM MPRIS ".chromium.instance"
|
||||
|
||||
static GDBusConnection *g_bus;
|
||||
static GHashTable *g_titles; /* browser pid -> char *title, while playing */
|
||||
static guint g_rescan;
|
||||
|
||||
typedef struct {
|
||||
GHashTable *titles;
|
||||
int pending;
|
||||
} Scan;
|
||||
|
||||
static void scan_done(Scan *scan) {
|
||||
if (--scan->pending > 0)
|
||||
return;
|
||||
if (g_titles)
|
||||
g_hash_table_unref(g_titles);
|
||||
g_titles = scan->titles;
|
||||
g_free(scan);
|
||||
emit(MM_TABS_MEDIA);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
Scan *scan;
|
||||
int pid;
|
||||
} Query;
|
||||
|
||||
static void on_player(GObject *src, GAsyncResult *res, gpointer d) {
|
||||
Query *q = d;
|
||||
g_autoptr(GVariant) ret =
|
||||
g_dbus_connection_call_finish(G_DBUS_CONNECTION(src), res, NULL);
|
||||
if (ret) {
|
||||
g_autoptr(GVariant) props = g_variant_get_child_value(ret, 0);
|
||||
g_autoptr(GVariant) meta =
|
||||
g_variant_lookup_value(props, "Metadata", G_VARIANT_TYPE_VARDICT);
|
||||
const char *status = NULL, *title = NULL;
|
||||
if (g_variant_lookup(props, "PlaybackStatus", "&s", &status) &&
|
||||
strcmp(status, "Playing") == 0 && meta &&
|
||||
g_variant_lookup(meta, "xesam:title", "&s", &title) && *title)
|
||||
g_hash_table_insert(q->scan->titles, GINT_TO_POINTER(q->pid),
|
||||
g_strdelimit(g_strdup(title), "\t\r\n", ' '));
|
||||
}
|
||||
scan_done(q->scan);
|
||||
g_free(q);
|
||||
}
|
||||
|
||||
static void on_names(GObject *src, GAsyncResult *res, gpointer d) {
|
||||
(void)d;
|
||||
g_autoptr(GVariant) ret =
|
||||
g_dbus_connection_call_finish(G_DBUS_CONNECTION(src), res, NULL);
|
||||
if (!ret)
|
||||
return;
|
||||
Scan *scan = g_new0(Scan, 1);
|
||||
scan->titles = g_hash_table_new_full(NULL, NULL, NULL, g_free);
|
||||
scan->pending = 1;
|
||||
g_autoptr(GVariantIter) it = NULL;
|
||||
const char *name;
|
||||
g_variant_get(ret, "(as)", &it);
|
||||
while (g_variant_iter_next(it, "&s", &name)) {
|
||||
if (!g_str_has_prefix(name, MPRIS_CHROMIUM))
|
||||
continue;
|
||||
int pid = atoi(name + strlen(MPRIS_CHROMIUM));
|
||||
if (pid <= 0)
|
||||
continue;
|
||||
Query *q = g_new0(Query, 1);
|
||||
q->scan = scan;
|
||||
q->pid = pid;
|
||||
scan->pending++;
|
||||
g_dbus_connection_call(
|
||||
G_DBUS_CONNECTION(src), name, "/org/mpris/MediaPlayer2",
|
||||
"org.freedesktop.DBus.Properties", "GetAll",
|
||||
g_variant_new("(s)", MPRIS ".Player"), G_VARIANT_TYPE("(a{sv})"),
|
||||
G_DBUS_CALL_FLAGS_NO_AUTO_START, 2000, NULL, on_player, q);
|
||||
}
|
||||
scan_done(scan);
|
||||
}
|
||||
|
||||
static gboolean rescan(gpointer d) {
|
||||
(void)d;
|
||||
g_rescan = 0;
|
||||
g_dbus_connection_call(g_bus, "org.freedesktop.DBus",
|
||||
"/org/freedesktop/DBus", "org.freedesktop.DBus",
|
||||
"ListNames", NULL, G_VARIANT_TYPE("(as)"),
|
||||
G_DBUS_CALL_FLAGS_NO_AUTO_START, 2000, NULL, on_names,
|
||||
NULL);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void on_mpris_signal(GDBusConnection *c, const char *sender,
|
||||
const char *path, const char *iface,
|
||||
const char *signal, GVariant *params, gpointer d) {
|
||||
(void)c; (void)sender; (void)path; (void)iface; (void)signal; (void)params;
|
||||
(void)d;
|
||||
if (!g_rescan)
|
||||
g_rescan = g_timeout_add(100, rescan, NULL);
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_tabs_watch_media(void) {
|
||||
if (g_bus)
|
||||
return;
|
||||
g_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
if (!g_bus)
|
||||
return;
|
||||
g_dbus_connection_signal_subscribe(
|
||||
g_bus, "org.freedesktop.DBus", "org.freedesktop.DBus",
|
||||
"NameOwnerChanged", "/org/freedesktop/DBus", MPRIS,
|
||||
G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE, on_mpris_signal, NULL, NULL);
|
||||
g_dbus_connection_signal_subscribe(
|
||||
g_bus, NULL, "org.freedesktop.DBus.Properties", "PropertiesChanged",
|
||||
"/org/mpris/MediaPlayer2", MPRIS ".Player", G_DBUS_SIGNAL_FLAGS_NONE,
|
||||
on_mpris_signal, NULL, NULL);
|
||||
rescan(NULL);
|
||||
}
|
||||
|
||||
/* "pid\ttitle\n" for every browser that is playing. */
|
||||
MOONBIT_FFI_EXPORT moonbit_bytes_t mm_tabs_media(void) {
|
||||
g_autoptr(GString) out = g_string_new(NULL);
|
||||
GHashTableIter it;
|
||||
gpointer pid, title;
|
||||
if (g_titles) {
|
||||
g_hash_table_iter_init(&it, g_titles);
|
||||
while (g_hash_table_iter_next(&it, &pid, &title))
|
||||
g_string_append_printf(out, "%d\t%s\n", GPOINTER_TO_INT(pid),
|
||||
(char *)title);
|
||||
}
|
||||
return to_bytes(out->str, out->len);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Smoke-test stand-in for a browser: plays a stream and reports it as a tab.
|
||||
|
||||
fake-browser.py <moonmix-tabs-host> <wav>: starts the host as its child, like a
|
||||
browser does, then pw-play (its "audio service") and a moment later one audible
|
||||
tab. Exits when stdin closes.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def message(tabs):
|
||||
body = json.dumps({"tabs": tabs}).encode()
|
||||
return struct.pack("=I", len(body)) + body
|
||||
|
||||
|
||||
def play():
|
||||
# exec keeps the pid the stream announces.
|
||||
os.execvp("pw-play", ["pw-play", "-P", json.dumps({
|
||||
"application.name": "Fake Browser",
|
||||
"application.process.id": str(os.getpid()),
|
||||
"media.name": "Playback",
|
||||
}), sys.argv[2]])
|
||||
|
||||
|
||||
host = subprocess.Popen([sys.argv[1]], stdin=subprocess.PIPE)
|
||||
host.stdin.write(message([]))
|
||||
host.stdin.flush()
|
||||
time.sleep(3) # let it connect to PipeWire
|
||||
audio = os.fork()
|
||||
if audio == 0:
|
||||
play()
|
||||
time.sleep(0.5)
|
||||
host.stdin.write(message([{"id": 7, "title": "Smoke test tab", "audible": True}]))
|
||||
host.stdin.flush()
|
||||
sys.stdin.read()
|
||||
os.kill(audio, 15)
|
||||
host.stdin.close()
|
||||
host.wait(5)
|
||||
@@ -1,79 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Install the browser tab host and extension for the current user.
|
||||
|
||||
Copies moonmix-tabs-host and the extension, and registers the host with every
|
||||
Chromium-family browser that has a profile. Loading the extension is up to the
|
||||
user. --uninstall removes everything again.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
NAME = "org.latha.moonmix.tabs"
|
||||
BROWSERS = (
|
||||
"google-chrome", "google-chrome-beta", "google-chrome-unstable", "chromium",
|
||||
"BraveSoftware/Brave-Browser", "microsoft-edge", "vivaldi",
|
||||
)
|
||||
|
||||
|
||||
def extension_id(manifest):
|
||||
digest = hashlib.sha256(base64.b64decode(manifest["key"])).hexdigest()[:32]
|
||||
return "".join(chr(ord("a") + int(c, 16)) for c in digest)
|
||||
|
||||
|
||||
def main():
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
config = Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config")
|
||||
data = Path(os.environ.get("XDG_DATA_HOME") or Path.home() / ".local/share")
|
||||
host = Path.home() / ".local/bin/moonmix-tabs-host"
|
||||
extension = data / "moonmix/extension"
|
||||
registered = [config / b / "NativeMessagingHosts" / f"{NAME}.json" for b in BROWSERS]
|
||||
|
||||
if sys.argv[1:] == ["--uninstall"]:
|
||||
for path in [*registered, host]:
|
||||
path.unlink(missing_ok=True)
|
||||
shutil.rmtree(extension, ignore_errors=True)
|
||||
print("Removed. Also remove the extension in the browser.")
|
||||
return
|
||||
|
||||
built = root / "_build/native/release/build/cmd/moonmix-tabs-host/moonmix-tabs-host.exe"
|
||||
if not built.exists():
|
||||
sys.exit("Build first: moon build --target native --release")
|
||||
host.parent.mkdir(parents=True, exist_ok=True)
|
||||
# Replace, not overwrite: the old one may be running.
|
||||
temporary = host.with_name(host.name + ".new")
|
||||
shutil.copyfile(built, temporary)
|
||||
temporary.chmod(0o755)
|
||||
temporary.replace(host)
|
||||
shutil.copytree(root / "extension", extension, dirs_exist_ok=True)
|
||||
|
||||
origin = extension_id(json.loads((extension / "manifest.json").read_text()))
|
||||
manifest = json.dumps({
|
||||
"name": NAME,
|
||||
"description": "moonmix browser tab names",
|
||||
"path": str(host),
|
||||
"type": "stdio",
|
||||
"allowed_origins": [f"chrome-extension://{origin}/"],
|
||||
}, indent=2)
|
||||
found = False
|
||||
for path in registered:
|
||||
# Only browsers that are in use here.
|
||||
if path.parent.parent.is_dir():
|
||||
path.parent.mkdir(exist_ok=True)
|
||||
path.write_text(manifest + "\n")
|
||||
print(f"Registered: {path}")
|
||||
found = True
|
||||
if not found:
|
||||
print("No supported browser profile found; nothing registered.")
|
||||
print(f"Installed host: {host}")
|
||||
print("Now open the browser's extensions page (chrome://extensions), turn on")
|
||||
print(f"Developer mode, choose 'Load unpacked' and select:\n {extension}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -35,14 +35,6 @@ set -- podman run --rm --pull=never \
|
||||
--mount "type=bind,src=$wayland_socket,dst=/run/moonmix/wayland-0,ro" \
|
||||
--mount "type=bind,src=$pipewire_socket,dst=/run/moonmix/pipewire-0,ro"
|
||||
|
||||
# Browser tab names published by the host's moonmix-tabs-host. Created here so
|
||||
# that names also appear when the browser starts after the mixer.
|
||||
tabs_dir=$XDG_RUNTIME_DIR/moonmix
|
||||
mkdir -p -m 700 "$tabs_dir"
|
||||
set -- "$@" \
|
||||
--mount "type=bind,src=$tabs_dir,dst=/run/moonmix/tabs,ro" \
|
||||
--env MOONMIX_TABS_DIR=/run/moonmix/tabs
|
||||
|
||||
# The portal supplies desktop appearance settings. Do not expose the rest of
|
||||
# XDG_RUNTIME_DIR (which can contain credentials and unrelated service sockets).
|
||||
if [ -S "$XDG_RUNTIME_DIR/bus" ]; then
|
||||
|
||||
@@ -13,7 +13,6 @@ set -eu
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
BUILD="$ROOT/_build/native/debug/build/cmd"
|
||||
PROBE="$BUILD/moonmix-probe/moonmix-probe.exe"
|
||||
TABS_HOST="$BUILD/moonmix-tabs-host/moonmix-tabs-host.exe"
|
||||
GUI="$BUILD/moonmix/moonmix.exe"
|
||||
SHOTS="${1:-}"
|
||||
|
||||
@@ -50,19 +49,12 @@ CONF
|
||||
|
||||
# Ubuntu's WirePlumber asks snapd before granting clients access; there is
|
||||
# no snapd in a sandbox/CI container, so turn that off for the test session.
|
||||
# No hardware either: the test noise must not reach the real speakers.
|
||||
mkdir -p "$XDG_CONFIG_HOME/wireplumber/wireplumber.conf.d"
|
||||
cat > "$XDG_CONFIG_HOME/wireplumber/wireplumber.conf.d/moonmix-test.conf" <<'CONF'
|
||||
wireplumber.profiles = {
|
||||
main = {
|
||||
support.snapd-permission-prompting = disabled
|
||||
script.client.access-snap = disabled
|
||||
monitor.alsa = disabled
|
||||
monitor.alsa-midi = disabled
|
||||
monitor.bluez = disabled
|
||||
monitor.bluez-midi = disabled
|
||||
monitor.libcamera = disabled
|
||||
monitor.v4l2 = disabled
|
||||
}
|
||||
}
|
||||
CONF
|
||||
@@ -168,21 +160,6 @@ meter() {
|
||||
meter "${STREAM:-0}"
|
||||
meter test_speakers
|
||||
|
||||
# Browser tab names: a fake browser with a real tab host.
|
||||
if command -v python3 >/dev/null; then
|
||||
echo "### browser tab names"
|
||||
mkfifo "$LOGS/browser.in"
|
||||
python3 "$ROOT/tools/fake-browser.py" "$TABS_HOST" "$LOGS/noise.wav" \
|
||||
<"$LOGS/browser.in" >"$LOGS/browser.log" 2>&1 & BROWSER=$!; PIDS="$PIDS $BROWSER"
|
||||
exec 5>"$LOGS/browser.in"
|
||||
wait_for 'Smoke test tab | ' || { fail=1; cat "$LOGS/browser.log" "$XDG_RUNTIME_DIR"/moonmix/* || true; "$PROBE" || true; }
|
||||
exec 5>&-
|
||||
wait "$BROWSER" || { echo "FAIL: fake browser"; cat "$LOGS/browser.log"; fail=1; }
|
||||
if [ -n "$(ls "$XDG_RUNTIME_DIR/moonmix")" ]; then echo "FAIL: tab host left its file"; fail=1; fi
|
||||
else
|
||||
echo "python3 not found; skipping browser tab names"
|
||||
fi
|
||||
|
||||
if [ "$fail" != 0 ]; then
|
||||
echo "### diagnostics"
|
||||
echo "--- pw-play playback:"; cat "$LOGS/play.log"
|
||||
|
||||
@@ -92,15 +92,9 @@ class ContainerTests(unittest.TestCase):
|
||||
self.assertEqual(self.mounts(), [
|
||||
f"type=bind,src={self.runtime}/wayland-test,dst=/run/moonmix/wayland-0,ro",
|
||||
f"type=bind,src={self.runtime}/pipewire-0,dst=/run/moonmix/pipewire-0,ro",
|
||||
f"type=bind,src={self.runtime}/moonmix,dst=/run/moonmix/tabs,ro",
|
||||
])
|
||||
self.assertIn("DBUS_SESSION_BUS_ADDRESS=unix:path=/run/moonmix/no-bus", arguments)
|
||||
|
||||
def test_tab_names_directory_is_private_and_read_only(self):
|
||||
self.assertEqual(self.launch().returncode, 0)
|
||||
self.assertEqual((self.runtime / "moonmix").stat().st_mode & 0o777, 0o700)
|
||||
self.assertIn("MOONMIX_TABS_DIR=/run/moonmix/tabs", self.podman_arguments())
|
||||
|
||||
def test_session_bus_is_optional_and_mounted_individually(self):
|
||||
self.bind_socket(self.runtime / "bus")
|
||||
self.assertEqual(self.launch().returncode, 0)
|
||||
@@ -123,7 +117,6 @@ class ContainerTests(unittest.TestCase):
|
||||
self.assertEqual(self.mounts(), [
|
||||
f"type=bind,src={wayland},dst=/run/moonmix/wayland-0,ro",
|
||||
f"type=bind,src={pipewire},dst=/run/moonmix/pipewire-0,ro",
|
||||
f"type=bind,src={self.runtime}/moonmix,dst=/run/moonmix/tabs,ro",
|
||||
])
|
||||
|
||||
def test_pipewire_runtime_remote_and_image_overrides(self):
|
||||
@@ -277,7 +270,6 @@ class ContainerTests(unittest.TestCase):
|
||||
self.assertEqual(mounts, [
|
||||
f"type=bind,src={self.runtime}/wayland-test,dst=/run/moonmix/wayland-0,ro",
|
||||
f"type=bind,src={self.runtime}/pipewire-0,dst=/run/moonmix/pipewire-0,ro",
|
||||
f"type=bind,src={self.runtime}/moonmix,dst=/run/moonmix/tabs,ro",
|
||||
f"type=bind,src={user_icons},dst=/run/moonmix/host/user/icons,ro",
|
||||
f"type=bind,src={sys_pixmaps},dst=/run/moonmix/host/usr/pixmaps,ro",
|
||||
f"type=bind,src={sys_apps},dst=/run/moonmix/host/usr/applications,ro",
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import {
|
||||
"geordi/moonmix/model",
|
||||
"moonbitlang/core/encoding/utf8",
|
||||
"moonbitlang/core/string",
|
||||
}
|
||||
|
||||
supported_targets = "-all+native"
|
||||
|
||||
@@ -68,12 +68,6 @@ extern "C" fn ffi_node_exists(id : Int32) -> Int32 = "mm_wp_node_exists"
|
||||
#borrow(key)
|
||||
extern "C" fn ffi_node_prop(id : Int32, key : Bytes) -> Bytes = "mm_wp_node_prop"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_node_running(id : Int32) -> Int32 = "mm_wp_node_running"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_parent_pid(pid : Int32) -> Int32 = "mm_wp_parent_pid"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_query_volume(id : Int32) -> Int32 = "mm_wp_query_volume"
|
||||
|
||||
@@ -210,9 +204,6 @@ pub fn read_node(id : Int32) -> @model.Node? {
|
||||
node_prop(id, "application.id")
|
||||
}
|
||||
}
|
||||
let pid = @string.parse_int(node_prop(id, "application.process.id")) catch {
|
||||
_ => 0
|
||||
}
|
||||
Some(
|
||||
@model.Node::new(
|
||||
id,
|
||||
@@ -226,9 +217,6 @@ pub fn read_node(id : Int32) -> @model.Node? {
|
||||
bus=node_prop(id, "device.bus"),
|
||||
app_binary=node_prop(id, "application.process.binary"),
|
||||
app_id~,
|
||||
serial=node_prop(id, "object.serial"),
|
||||
parent_pid=ffi_parent_pid(pid),
|
||||
running=ffi_node_running(id) != 0,
|
||||
volumes~,
|
||||
mute~,
|
||||
),
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* details it needs through small accessor functions. All calls happen on the
|
||||
* GLib default main context (shared with GTK), so no locking is needed.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wp/wp.h>
|
||||
#include <pipewire/keys.h>
|
||||
@@ -105,21 +104,12 @@ static void on_node_props(GObject *obj, GParamSpec *pspec, gpointer data) {
|
||||
emit(MM_EV_NODE_CHANGED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(obj)));
|
||||
}
|
||||
|
||||
static void on_node_state(WpNode *node, WpNodeState old, WpNodeState now,
|
||||
gpointer data) {
|
||||
(void)data;
|
||||
/* Only running / not running matters. */
|
||||
if ((old == WP_NODE_STATE_RUNNING) != (now == WP_NODE_STATE_RUNNING))
|
||||
emit(MM_EV_NODE_CHANGED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(node)));
|
||||
}
|
||||
|
||||
static void on_object_added(WpObjectManager *om, GObject *obj, gpointer d) {
|
||||
(void)om;
|
||||
(void)d;
|
||||
if (WP_IS_NODE(obj)) {
|
||||
g_signal_connect(obj, "notify::properties", G_CALLBACK(on_node_props),
|
||||
NULL);
|
||||
g_signal_connect(obj, "state-changed", G_CALLBACK(on_node_state), NULL);
|
||||
emit(MM_EV_NODE_ADDED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(obj)));
|
||||
} else if (WP_IS_LINK(obj)) {
|
||||
emit(MM_EV_LINKS_CHANGED, 0);
|
||||
@@ -131,7 +121,6 @@ static void on_object_removed(WpObjectManager *om, GObject *obj, gpointer d) {
|
||||
(void)d;
|
||||
if (WP_IS_NODE(obj)) {
|
||||
g_signal_handlers_disconnect_by_func(obj, on_node_props, NULL);
|
||||
g_signal_handlers_disconnect_by_func(obj, on_node_state, NULL);
|
||||
emit(MM_EV_NODE_REMOVED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(obj)));
|
||||
} else if (WP_IS_LINK(obj)) {
|
||||
emit(MM_EV_LINKS_CHANGED, 0);
|
||||
@@ -311,29 +300,6 @@ MOONBIT_FFI_EXPORT moonbit_bytes_t mm_wp_node_prop(int32_t id,
|
||||
return to_bytes(v);
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT int32_t mm_wp_node_running(int32_t id) {
|
||||
g_autoptr(WpNode) node = lookup_node((guint32)id);
|
||||
return node && wp_node_get_state(node, NULL) == WP_NODE_STATE_RUNNING;
|
||||
}
|
||||
|
||||
/* Parent of a process (Chrome's audio service -> the browser); 0 if unknown,
|
||||
* e.g. in a container with its own pid namespace. */
|
||||
MOONBIT_FFI_EXPORT int32_t mm_wp_parent_pid(int32_t pid) {
|
||||
char path[64];
|
||||
g_autofree char *stat = NULL;
|
||||
int ppid = 0;
|
||||
if (pid <= 0)
|
||||
return 0;
|
||||
g_snprintf(path, sizeof path, "/proc/%d/stat", pid);
|
||||
if (!g_file_get_contents(path, &stat, NULL, NULL))
|
||||
return 0;
|
||||
/* "pid (comm) state ppid ...": comm may itself contain ") ". */
|
||||
const char *p = strrchr(stat, ')');
|
||||
if (!p || sscanf(p + 1, " %*c %d", &ppid) != 1)
|
||||
return 0;
|
||||
return ppid;
|
||||
}
|
||||
|
||||
/* Volume of the last queried node. */
|
||||
#define MM_MAX_CH 64
|
||||
static double g_vol[MM_MAX_CH];
|
||||
|
||||
Reference in new issue
Block a user