Files
GOGUpdater/GOGUpdater.py
T

59 lines
1.6 KiB
Python

"""GOGUpdater GUI entry point."""
import sys
from loguru import logger
from PySide6.QtWidgets import QApplication
from src.api import GogApi
from src.auth import AuthManager
from src.config import DEFAULT_CONFIG_DIR, AppConfig
from src.constants import APP_TITLE
from src.ui.main_window import MainWindow
def _setup_logging(config_dir) -> None:
"""Log DEBUG to stderr and to a rotating file for diagnostics."""
log_file = config_dir / "gogupdater.log"
# loguru is already thread-safe (per-sink lock); avoid enqueue=True, which
# spins up a multiprocessing queue and leaks semaphores on a hard crash.
logger.add(
log_file,
level="DEBUG",
rotation="2 MB",
retention=3,
backtrace=True,
diagnose=True,
)
logger.info(f"Logging to {log_file}")
# Make sure exceptions raised inside Qt slots are logged instead of swallowed.
def _excepthook(exc_type, exc_value, exc_tb):
logger.opt(exception=(exc_type, exc_value, exc_tb)).error("Uncaught exception")
sys.__excepthook__(exc_type, exc_value, exc_tb)
sys.excepthook = _excepthook
def main() -> None:
config_dir = DEFAULT_CONFIG_DIR
config_dir.mkdir(parents=True, exist_ok=True)
_setup_logging(config_dir)
logger.info(f"Starting {APP_TITLE}")
auth = AuthManager(config_dir)
api = GogApi(auth)
config = AppConfig(config_dir)
app = QApplication(sys.argv)
window = MainWindow(auth, api, config)
window.show()
logger.info("Application window shown")
sys.exit(app.exec())
if __name__ == "__main__":
main()