blitztext-app-linux/linux/blitztext/autostart.py
mARTin-B78 b0b7a8c95e gtksettings: align Input tab labels to uniform 175px width; autostart: add 12s delay
All rows in the Input tab (labeled, key_field, url_field, sound_field) now share
a single LW=175 label width, eliminating the jagged left edge on input fields.
Added X-GNOME-Autostart-Delay=12 to the .desktop entry so gnome-shell, AT-SPI,
and the input stack are fully initialised before Blitztext connects — fixes the
session crash on first login after installation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-08 20:00:33 +02:00

57 lines
1.6 KiB
Python

"""Launch-on-login via a freedesktop autostart entry.
Writes ~/.config/autostart/blitztext.desktop so the tray starts with the GNOME
session. No root needed.
"""
from __future__ import annotations
import os
import shutil
import sys
from pathlib import Path
_AUTOSTART_DIR = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "autostart"
_ENTRY = _AUTOSTART_DIR / "blitztext.desktop"
def _exec_command() -> str:
"""Launch the *currently running* copy on login.
If we're running from a source checkout (not the installed /opt copy or a
site-packages install), launch that exact source with PYTHONPATH so edits
stay live. Otherwise prefer the installed `blitztext` launcher.
"""
import blitztext
pkg_parent = str(Path(blitztext.__file__).resolve().parent.parent)
from_source = not pkg_parent.startswith("/opt/") and "site-packages" not in pkg_parent
if from_source:
return f"env PYTHONPATH={pkg_parent} {sys.executable} -m blitztext tray"
launcher = shutil.which("blitztext")
if launcher:
return f"{launcher} tray"
return f"{sys.executable} -m blitztext tray"
def is_enabled() -> bool:
return _ENTRY.exists()
def set_enabled(enabled: bool) -> None:
if not enabled:
_ENTRY.unlink(missing_ok=True)
return
_AUTOSTART_DIR.mkdir(parents=True, exist_ok=True)
_ENTRY.write_text(
"[Desktop Entry]\n"
"Type=Application\n"
"Name=Blitztext\n"
f"Exec={_exec_command()}\n"
"Icon=blitztext\n"
"Terminal=false\n"
"X-GNOME-Autostart-enabled=true\n"
"X-GNOME-Autostart-Delay=12\n",
encoding="utf-8",
)