"""XDG autostart entry for starting minimized at login.""" from __future__ import annotations import os import shutil import sys from pathlib import Path AUTOSTART_FILE = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "autostart" / "k65studio.desktop" def _exec_line() -> str: launcher = shutil.which("k65studio") if launcher: return f"{launcher} --minimized" project = Path(__file__).resolve().parent.parent return f"sh -c 'cd \"{project}\" && exec \"{sys.executable}\" -m k65studio --minimized'" def is_enabled() -> bool: return AUTOSTART_FILE.exists() def set_enabled(enabled: bool) -> None: if not enabled: AUTOSTART_FILE.unlink(missing_ok=True) return AUTOSTART_FILE.parent.mkdir(parents=True, exist_ok=True) AUTOSTART_FILE.write_text( "[Desktop Entry]\n" "Type=Application\n" "Name=K65 Studio\n" "Comment=Corsair K65 PLUS Wireless Beleuchtung und Einstellungen\n" f"Exec={_exec_line()}\n" "Icon=k65studio\n" "X-GNOME-Autostart-enabled=true\n" "X-KDE-autostart-after=panel\n" )