Name Chrome streams after their browser tabs
A browser extension reports audible tabs to moonmix-tabs-host, which matches them to PipeWire streams by time and publishes the names for the mixer; streams of one tab share a row. Ambiguous streams keep the browser's name. Without the extension, a browser's only running stream shows its MPRIS title. The smoke test no longer claims real audio hardware. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b61d504234
commit
e16cc1b2ad
31 files changed
+1830
-15
No files matched your search
+61
-1
@@ -40,6 +40,9 @@ 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
|
||||
}
|
||||
@@ -62,6 +65,9 @@ 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 {
|
||||
@@ -77,6 +83,9 @@ pub fn Node::new(
|
||||
bus,
|
||||
app_binary,
|
||||
app_id,
|
||||
serial,
|
||||
parent_pid,
|
||||
running,
|
||||
volumes,
|
||||
mute,
|
||||
}
|
||||
@@ -101,6 +110,10 @@ 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
|
||||
}
|
||||
@@ -111,11 +124,20 @@ 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, }
|
||||
{
|
||||
nodes: {},
|
||||
links: [],
|
||||
default_sink: -1,
|
||||
default_source: -1,
|
||||
tab_names: Map([]),
|
||||
media_titles: Map([]),
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -152,6 +174,16 @@ 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()
|
||||
@@ -226,6 +258,34 @@ 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.)
|
||||
|
||||
Reference in new issue
Block a user