diff --git a/api/schema.py b/api/schema.py index fdfdd2b..42f328f 100644 --- a/api/schema.py +++ b/api/schema.py @@ -46,18 +46,27 @@ def _default_command() -> str: """Return the default shell command to run wecker.py from crontab.""" project_root = _project_root() python_exec = sys.executable - return f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1" + runtime_dir = f"/run/user/{os.getuid()}" + return ( + f"cd {project_root} && " + f"XDG_RUNTIME_DIR={runtime_dir} SDL_AUDIODRIVER=pulse " + f"{python_exec} wecker.py >> wecker.log 2>&1" + ) def _start_wecker_process() -> subprocess.Popen: """Start wecker.py without invoking a shell.""" project_root = _project_root() + env = os.environ.copy() + env.setdefault("SDL_AUDIODRIVER", "pulse") + env.setdefault("XDG_RUNTIME_DIR", f"/run/user/{os.getuid()}") return subprocess.Popen( [sys.executable, str(project_root / "wecker.py")], cwd=project_root, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True, + env=env, ) diff --git a/wecker.py b/wecker.py index a090f7a..782b282 100644 --- a/wecker.py +++ b/wecker.py @@ -6,6 +6,9 @@ import random import sys import os import fcntl + +# Use PulseAudio/PipeWire audio driver to avoid ALSA device-busy errors. +os.environ.setdefault("SDL_AUDIODRIVER", "pulse") from logging.handlers import RotatingFileHandler from common import PID_FILE