#!/usr/bin/env python3 import sys import os import json from PySide6.QtWidgets import QApplication from qt_material import apply_stylesheet from hookvision.config_loader import load_config from hookvision.main_window import MainWindow import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def _autostart_diag(): import winreg log = [] log.append(f"sys.executable = {sys.executable}") log.append(f"sys.platform = {sys.platform}") log.append(f"frozen = {getattr(sys, 'frozen', False)}") config_dir = os.path.join(os.environ.get("APPDATA", os.path.expanduser("~")), "HookVision") config_path = os.path.join(config_dir, "autostart.json") log.append(f"config_path = {config_path}") try: os.makedirs(config_dir, exist_ok=True) with open(config_path, "w", encoding="utf-8") as f: json.dump({"enabled": True}, f) with open(config_path, "r", encoding="utf-8") as f: data = json.load(f) log.append(f"JSON OK: {data}") os.remove(config_path) except Exception as e: log.append(f"JSON FAIL: {e}") key = r"Software\Microsoft\Windows\CurrentVersion\Run" try: with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key, 0, winreg.KEY_SET_VALUE) as rk: winreg.SetValueEx(rk, "HookVision", 0, winreg.REG_SZ, sys.executable) with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key, 0, winreg.KEY_READ) as rk: val, _ = winreg.QueryValueEx(rk, "HookVision") log.append(f"Registry OK: {val}") with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key, 0, winreg.KEY_SET_VALUE) as rk: winreg.DeleteValue(rk, "HookVision") except Exception as e: log.append(f"Registry FAIL: {e}") msg = "\n".join(log) print(msg) with open("autostart_diag.txt", "w", encoding="utf-8") as f: f.write(msg) def main(): if "--autostart-test" in sys.argv: _autostart_diag() return app = QApplication(sys.argv) apply_stylesheet(app, theme='dark_teal.xml') if getattr(sys, 'frozen', False): config_path = os.path.join(sys._MEIPASS, 'config.ini') else: config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.ini') config = load_config(config_path) window = MainWindow(config) window.show() sys.exit(app.exec()) if __name__ == "__main__": main()