Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions default/systemd/user/mpris-proxy.service.d/10-omarchy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Let Bluetooth headsets drive the media player.
#
# Headsets send transport control as AVRCP passthrough: play/pause, next and
# previous from the buttons or stem gestures, and the pause that earbuds with
# in-ear detection emit when one is taken out. bluez only routes those to a
# player registered on org.bluez.Media1, and with nothing registered it drops
# them, so the buttons do nothing and playback runs on into an ear that is no
# longer listening. mpris-proxy is that registration, exporting session MPRIS
# players to bluez.
#
# bluez-utils ships the unit but leaves it disabled, and it carries no
# conditions or Restart=. mpris-proxy exits 1 ("Can't get on system bus") when
# bluetoothd is unreachable at startup, so enabling it as shipped leaves a
# failed unit on every machine without a usable adapter. The two conditions
# mirror bt-agent.service and skip it cleanly there instead.
#
# Restart= covers mpris-proxy itself dying, and nothing more. It does not
# recover a bluetoothd restart: a running proxy survives that without exiting,
# logging "org.bluez disappeared" and then "org.bluez appeared", so systemd is
# never involved. A user unit cannot order itself against the system
# bluetooth.service, so recovering that case is out of reach from here.
[Unit]
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
ExecCondition=/usr/bin/systemctl is-active --quiet bluetooth.service
Restart=on-failure
RestartSec=2
1 change: 1 addition & 0 deletions install/user/first-run/enable-user-units.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -euo pipefail
systemctl --user daemon-reload
systemctl --user enable --now \
bt-agent.service \
mpris-proxy.service \
owed.service \
omarchy-recover-internal-monitor.service \
omarchy-sleep-lock.service \
Expand Down
23 changes: 23 additions & 0 deletions migrations/1788959623.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
echo "Enable the Bluetooth MPRIS proxy so headset transport controls reach the player"

# Only first-run enables the units we ship, so existing installs never picked
# this one up. The drop-in keeps it inert where there is no bluetooth, so it is
# safe to enable unconditionally here.

systemctl --user daemon-reload >/dev/null 2>&1 || true

# `systemctl enable` needs a live user manager, which an update from a TTY does
# not have, so fall back to writing the symlink it would have written. The unit
# bluez ships is WantedBy=default.target, not graphical-session.target.
if ! systemctl --user enable mpris-proxy.service >/dev/null 2>&1; then
wants_dir="$HOME/.config/systemd/user/default.target.wants"
mkdir -p "$wants_dir"
ln -sfn /usr/lib/systemd/user/mpris-proxy.service \
"$wants_dir/mpris-proxy.service"
fi

# Nothing to start into over SSH; the next login handles it. A failed start
# only delays headset button support, so it stays quiet.
if systemctl --user is-active --quiet default.target; then
systemctl --user start mpris-proxy.service >/dev/null 2>&1 || true
fi
13 changes: 13 additions & 0 deletions test/shell.d/systemd-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ pass "systemd-oomd acts on sustained memory stall"
grep -Fx 'systemctl enable systemd-oomd.service' "$ROOT/install/config/enable-services.sh" >/dev/null ||
fail "new installs ship the oomd drop-ins with the daemon that reads them disabled"
pass "new installs enable systemd-oomd"

mpris_dropin="$ROOT/default/systemd/user/mpris-proxy.service.d/10-omarchy.conf"
grep -Fx 'ConditionPathIsDirectory=/sys/class/bluetooth' "$mpris_dropin" >/dev/null ||
fail "the AVRCP bridge is pulled in on machines with no bluetooth subsystem"
grep -Fx 'ExecCondition=/usr/bin/systemctl is-active --quiet bluetooth.service' "$mpris_dropin" >/dev/null ||
fail "mpris-proxy exits 1 when bluetoothd is unreachable, so without this it leaves a failed unit instead of skipping"
grep -Fx 'Restart=on-failure' "$mpris_dropin" >/dev/null ||
fail "a crashed proxy stays dead and headset transport controls silently stop working"
pass "the AVRCP bridge stays inert without bluetooth and recovers from its own crash"
Comment on lines +108 to +115

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Package delivery goes unchecked

These tests check the repository copy of the drop-in, but not whether the package installs it where systemd reads it. If the package omits it, the tests still pass while users receive none of these guards. Add the drop-in and its destination to package_defaults in config-test.sh, which already checks package delivery for other service defaults.


grep -F 'mpris-proxy.service' "$first_run_units" >/dev/null ||
fail "first-run does not enable the AVRCP bridge, so bluez has no player registered and headset transport commands are discarded"
pass "first-run enables the bridge that carries headset play/pause into MPRIS"