#!/usr/bin/python3
"""Request network provisioning once in an approved installed desktop session."""
import os
from pathlib import Path
import subprocess
import sys
sys.path.insert(0, "/usr/local/lib/compact-desktop/consent")
from agreement_model import has_agreed

marker = Path(os.environ.get("XDG_STATE_HOME", str(Path.home() / ".local/state"))) / "newworld/artcraft-prompted"
if has_agreed() and not marker.exists():
    import time
    time.sleep(7)
    marker.parent.mkdir(parents=True, exist_ok=True)
    try:
        marker.touch(exist_ok=False)
    except FileExistsError:
        sys.exit(0)
    subprocess.run(["/usr/bin/pkexec", "/usr/local/lib/compact-artcraft/install-all"], check=False)
