From 0a1dbc78c645affdc32e6cd1daff5ddc8f3b8dd3 Mon Sep 17 00:00:00 2001 From: overspend1 Date: Sun, 21 Dec 2025 17:44:05 +0100 Subject: [PATCH] Open QR login in window when possible --- core/client.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/core/client.py b/core/client.py index 25df515..29f13c1 100644 --- a/core/client.py +++ b/core/client.py @@ -3,6 +3,8 @@ from __future__ import annotations import asyncio import subprocess import sys +import threading +import webbrowser from pathlib import Path from typing import Any, Optional @@ -145,7 +147,7 @@ class ClientWrapper: except Exception: pass if qr_open and saved_path: - self._open_file(saved_path) + self._open_qr_window(saved_path) def _save_qr_image(self, url: str, qr_path: str) -> Optional[Path]: try: @@ -160,6 +162,34 @@ class ClientWrapper: logger.info("QR image saved to %s", path) return path + def _open_qr_window(self, path: Path) -> None: + if self._try_tk_window(path): + return + self._open_file(path) + + def _try_tk_window(self, path: Path) -> bool: + try: + import tkinter as tk + except Exception: + return False + + def run_window() -> None: + try: + root = tk.Tk() + root.title("OverUB QR Login") + root.attributes("-topmost", True) + image = tk.PhotoImage(file=str(path)) + label = tk.Label(root, image=image) + label.image = image + label.pack() + root.mainloop() + except Exception: + return + + thread = threading.Thread(target=run_window, daemon=True) + thread.start() + return True + def _open_file(self, path: Path) -> None: try: if sys.platform.startswith("darwin"): @@ -169,7 +199,10 @@ class ClientWrapper: else: subprocess.run(["xdg-open", str(path)], check=False) except Exception: - logger.warning("Failed to open QR image automatically") + try: + webbrowser.open(path.as_uri()) + except Exception: + logger.warning("Failed to open QR image automatically") async def _prompt(self, prompt: str) -> str: loop = asyncio.get_event_loop()