Files
GOGUpdater/GOGUpdater.py
T

58 lines
1.5 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 AppConfig, DEFAULT_CONFIG_DIR
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"
logger.add(
log_file,
level="DEBUG",
rotation="2 MB",
retention=3,
backtrace=True,
diagnose=True,
enqueue=True, # thread-safe logging from worker threads
)
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()