#!/usr/bin/python3
"""Launcher for VolnOS Welcome (the first-login setup screen).

Installed to /usr/bin/volnos-welcome and started once per user from
/etc/xdg/autostart/volnos-welcome.desktop. To keep later logins instant it checks
the per-user stamp BEFORE importing GTK and exits immediately if the screen has
already been shown.

  volnos-welcome            run if not yet completed (the autostart behaviour)
  volnos-welcome --force    show it again regardless of the stamp (for testing)

Also runnable from a source checkout via:
    PYTHONPATH=partA-remix/welcome ./partA-remix/welcome/bin/volnos-welcome --force
"""
import os
import sys

# Prefer the installed location; fall back to the source tree for development.
_INSTALL_DIR = "/usr/lib/volnos-welcome"
if os.path.isdir(os.path.join(_INSTALL_DIR, "volnos_welcome")):
    sys.path.insert(0, _INSTALL_DIR)
else:
    sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

from volnos_welcome import welcome_is_done  # noqa: E402

if __name__ == "__main__":
    if "--force" not in sys.argv:
        # Only run for a REAL human account (uid >= 1000). This skips the
        # gnome-initial-setup system session and the GDM greeter, so the welcome
        # never appears over the account-creation wizard or stamps the wrong home.
        if hasattr(os, "geteuid") and os.geteuid() < 1000:
            sys.exit(0)
        if welcome_is_done():
            sys.exit(0)
    from volnos_welcome.application import main  # imported lazily (pulls in GTK)
    sys.exit(main())
