Files
moonmix/tools/moonmix-container
T
nandiandClaude Opus 5.5 e16cc1b2ad 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>
2026-11-29 19:26:29 -08:00

118 lines
4.9 KiB
Bash
Executable File

#!/bin/sh
# Run the local OCI image against the current user's Wayland/PipeWire session.
set -eu
fail() { printf 'moonmix-container: %s\n' "$*" >&2; exit 1; }
command -v podman >/dev/null 2>&1 || fail "install rootless Podman first"
[ "$#" -eq 0 ] || fail "this launcher does not take arguments"
[ -n "${XDG_RUNTIME_DIR:-}" ] || fail "XDG_RUNTIME_DIR is not set"
[ -n "${WAYLAND_DISPLAY:-}" ] || fail "a Wayland session is required"
uid=$(id -u)
gid=$(id -g)
[ "$uid" -ne 0 ] || fail "run this as your desktop user, not root"
case "$WAYLAND_DISPLAY" in
/*) wayland_socket=$WAYLAND_DISPLAY ;;
*) wayland_socket=$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY ;;
esac
case "${PIPEWIRE_REMOTE:-pipewire-0}" in
/*) pipewire_socket=$PIPEWIRE_REMOTE ;;
*) pipewire_socket=${PIPEWIRE_RUNTIME_DIR:-$XDG_RUNTIME_DIR}/${PIPEWIRE_REMOTE:-pipewire-0} ;;
esac
[ -S "$wayland_socket" ] || fail "Wayland socket not found: $wayland_socket"
[ -S "$pipewire_socket" ] || fail "PipeWire socket not found: $pipewire_socket"
set -- podman run --rm --pull=never \
--userns=keep-id --user "$uid:$gid" \
--network=none --cap-drop=all --security-opt=no-new-privileges \
--read-only \
--tmpfs /tmp:rw,nosuid,nodev \
--env XDG_ACTIVATION_TOKEN --env DESKTOP_STARTUP_ID \
--env XDG_RUNTIME_DIR=/tmp/moonmix-runtime \
--env PIPEWIRE_RUNTIME_DIR=/run/moonmix \
--env PIPEWIRE_REMOTE=pipewire-0 \
--env WAYLAND_DISPLAY=/run/moonmix/wayland-0 \
--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
set -- "$@" \
--mount "type=bind,src=$XDG_RUNTIME_DIR/bus,dst=/run/moonmix/bus,ro" \
--env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/moonmix/bus
else
set -- "$@" --env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/moonmix/no-bus
fi
# Mount only existing host icon / .desktop directories read-only so GIO and
# GtkIconTheme can resolve real full-colour host app icons without exposing $HOME.
host_root=${MOONMIX_HOST_ROOT:-}
if [ -n "${XDG_DATA_HOME:-}" ]; then
data_home=$XDG_DATA_HOME
elif [ -n "${HOME:-}" ]; then
data_home=$HOME/.local/share
else
data_home=
fi
host_xdg_dirs=
add_xdg_prefix() {
case ":$host_xdg_dirs:" in
*":$1:"*) ;;
*) host_xdg_dirs=${host_xdg_dirs:+$host_xdg_dirs:}$1 ;;
esac
}
if [ -n "$data_home" ]; then
if [ -d "$data_home/icons" ]; then
set -- "$@" --mount "type=bind,src=$data_home/icons,dst=/run/moonmix/host/user/icons,ro"
add_xdg_prefix /run/moonmix/host/user
fi
if [ -d "$data_home/applications" ]; then
set -- "$@" --mount "type=bind,src=$data_home/applications,dst=/run/moonmix/host/user/applications,ro"
add_xdg_prefix /run/moonmix/host/user
fi
if [ -d "$data_home/flatpak/exports/share/icons" ]; then
set -- "$@" --mount "type=bind,src=$data_home/flatpak/exports/share/icons,dst=/run/moonmix/host/flatpak-user/icons,ro"
add_xdg_prefix /run/moonmix/host/flatpak-user
fi
if [ -d "$data_home/flatpak/exports/share/applications" ]; then
set -- "$@" --mount "type=bind,src=$data_home/flatpak/exports/share/applications,dst=/run/moonmix/host/flatpak-user/applications,ro"
add_xdg_prefix /run/moonmix/host/flatpak-user
fi
fi
if [ -d "$host_root/var/lib/flatpak/exports/share/icons" ]; then
set -- "$@" --mount "type=bind,src=$host_root/var/lib/flatpak/exports/share/icons,dst=/run/moonmix/host/flatpak-sys/icons,ro"
add_xdg_prefix /run/moonmix/host/flatpak-sys
fi
if [ -d "$host_root/var/lib/flatpak/exports/share/applications" ]; then
set -- "$@" --mount "type=bind,src=$host_root/var/lib/flatpak/exports/share/applications,dst=/run/moonmix/host/flatpak-sys/applications,ro"
add_xdg_prefix /run/moonmix/host/flatpak-sys
fi
if [ -d "$host_root/usr/share/icons" ]; then
set -- "$@" --mount "type=bind,src=$host_root/usr/share/icons,dst=/run/moonmix/host/usr/icons,ro"
add_xdg_prefix /run/moonmix/host/usr
fi
if [ -d "$host_root/usr/share/pixmaps" ]; then
set -- "$@" --mount "type=bind,src=$host_root/usr/share/pixmaps,dst=/run/moonmix/host/usr/pixmaps,ro"
add_xdg_prefix /run/moonmix/host/usr
fi
if [ -d "$host_root/usr/share/applications" ]; then
set -- "$@" --mount "type=bind,src=$host_root/usr/share/applications,dst=/run/moonmix/host/usr/applications,ro"
add_xdg_prefix /run/moonmix/host/usr
fi
set -- "$@" --env "XDG_DATA_DIRS=${host_xdg_dirs:+$host_xdg_dirs:}/usr/local/share:/usr/share"
exec "$@" "${MOONMIX_IMAGE:-localhost/moonmix:latest}"