54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
"""Desktop application entry point."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from collections.abc import Sequence
|
|
|
|
from PySide6.QtCore import QTimer
|
|
from PySide6.QtWidgets import QApplication, QMessageBox
|
|
|
|
from javis.config.settings import ConfigurationError, Settings
|
|
from javis.core.provider_router import ApprovalChoice
|
|
from javis.core.runtime import build_javis_runtime
|
|
from javis.memory.sqlite_store import SessionStoreError
|
|
from javis.memory.usage_store import UsageStoreError
|
|
from javis.ui.chat_controller import DesktopController
|
|
from javis.ui.main_window import MainWindow
|
|
from javis.ui.workers import ApprovalBridge
|
|
|
|
|
|
def run_gui(argv: Sequence[str] | None = None) -> int:
|
|
application = QApplication.instance() or QApplication(list(argv or []))
|
|
application.setApplicationName("Javis Desktop")
|
|
approval_bridge = ApprovalBridge()
|
|
try:
|
|
settings = Settings.from_env()
|
|
runtime = build_javis_runtime(
|
|
settings,
|
|
approval_callback=lambda _decision: ApprovalChoice.CANCEL,
|
|
notice_callback=approval_bridge.notice_received.emit,
|
|
)
|
|
except (ConfigurationError, SessionStoreError, UsageStoreError) as exc:
|
|
QMessageBox.critical(None, "Javis konnte nicht starten", str(exc))
|
|
return 2
|
|
window = MainWindow(DesktopController(runtime), approval_bridge)
|
|
window.show()
|
|
smoke_exit = os.environ.get("JAVIS_GUI_SMOKE_EXIT_MS")
|
|
if smoke_exit:
|
|
try:
|
|
delay = max(1, min(int(smoke_exit), 10_000))
|
|
except ValueError:
|
|
delay = 500
|
|
QTimer.singleShot(delay, application.quit)
|
|
return application.exec()
|
|
|
|
|
|
def main() -> int:
|
|
return run_gui(sys.argv)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|