From a8fe5d1eab114dcb938068a785b9c11875151836 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 21 Apr 2026 16:44:05 -0400 Subject: [PATCH] More work on gettings things working. --- etc/sudoers.d/stormux-audio-state | 1 + .../stormux-persistent-state.conf | 8 ++++++ home/stormux/.local/bin/game_launcher.py | 4 +++ usr/lib/stormux/stormux_alsa_state.sh | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 etc/sudoers.d/stormux-audio-state create mode 100644 etc/systemd/system/alsa-restore.service.d/stormux-persistent-state.conf create mode 100755 usr/lib/stormux/stormux_alsa_state.sh diff --git a/etc/sudoers.d/stormux-audio-state b/etc/sudoers.d/stormux-audio-state new file mode 100644 index 0000000..52006f6 --- /dev/null +++ b/etc/sudoers.d/stormux-audio-state @@ -0,0 +1 @@ +%wheel ALL=(ALL) NOPASSWD: /usr/lib/stormux/stormux_alsa_state.sh * diff --git a/etc/systemd/system/alsa-restore.service.d/stormux-persistent-state.conf b/etc/systemd/system/alsa-restore.service.d/stormux-persistent-state.conf new file mode 100644 index 0000000..e7ae6b1 --- /dev/null +++ b/etc/systemd/system/alsa-restore.service.d/stormux-persistent-state.conf @@ -0,0 +1,8 @@ +[Unit] +RequiresMountsFor=/home/stormux/.local/state/alsa + +[Service] +ExecStart= +ExecStart=-/usr/lib/stormux/stormux_alsa_state.sh restore +ExecStop= +ExecStop=-/usr/lib/stormux/stormux_alsa_state.sh store diff --git a/home/stormux/.local/bin/game_launcher.py b/home/stormux/.local/bin/game_launcher.py index cca7dcd..dba7567 100755 --- a/home/stormux/.local/bin/game_launcher.py +++ b/home/stormux/.local/bin/game_launcher.py @@ -333,6 +333,10 @@ class VoicedMenu: ['pactl', 'set-sink-volume', '@DEFAULT_SINK@', f'{volumePercent}%'], check=True ) + subprocess.run( + ['sudo', '-n', '/usr/lib/stormux/stormux_alsa_state.sh', 'store'], + check=False + ) self.volume = volumePercent self.save_settings() return True diff --git a/usr/lib/stormux/stormux_alsa_state.sh b/usr/lib/stormux/stormux_alsa_state.sh new file mode 100755 index 0000000..307d8f0 --- /dev/null +++ b/usr/lib/stormux/stormux_alsa_state.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -euo pipefail + +stateDir="${STORMUX_ALSA_STATE_DIR:-/home/stormux/.local/state/alsa}" +stateFile="${stateDir}/asound.state" +action="${1:-}" + +usage() { + printf 'Usage: %s restore|store\n' "${0##*/}" >&2 +} + +case "$action" in + restore) + if [[ ! -f "$stateFile" ]]; then + exit 0 + fi + exec /usr/bin/alsactl -f "$stateFile" restore + ;; + store) + install -d -o root -g root -m 755 "$stateDir" + exec /usr/bin/alsactl -f "$stateFile" store + ;; + *) + usage + exit 2 + ;; +esac