zapret-kvn/xray_fluent/platform/windows/startup.py
loop-uh d5a4715771
Some checks failed
Windows project source guards / test (push) Has been cancelled
feat: use official Amnezia transport and organize runtime modules
2026-09-06 00:14:08 +03:00

35 lines
1 KiB
Python

from __future__ import annotations
from pathlib import Path
import sys
if sys.platform == "win32":
import winreg
RUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
def set_startup_enabled(app_name: str, enabled: bool, command: str) -> None:
if sys.platform != "win32":
return
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, RUN_KEY, 0, winreg.KEY_SET_VALUE) as key:
if enabled:
winreg.SetValueEx(key, app_name, 0, winreg.REG_SZ, command)
else:
try:
winreg.DeleteValue(key, app_name)
except FileNotFoundError:
pass
def build_startup_command() -> str:
if getattr(sys, "frozen", False):
exe = Path(sys.executable).resolve()
return f'"{exe}" --tray'
base_dir = Path(__file__).resolve().parents[3]
script = base_dir / "main.py"
venv_pythonw = base_dir / ".venv" / "Scripts" / "pythonw.exe"
python_exe = venv_pythonw if venv_pythonw.exists() else Path(sys.executable).resolve()
return f'"{python_exe}" "{script}" --tray'