feat(ui): Qt progress window with Prism-Launcher-inspired dark palette
cloud-sync now ships a real Qt UI alongside the tkinter fallback.
Architecture:
- HeadlessProgress: --no-gui path, plain stdout
- TkProgressWindow: stdlib fallback when Qt isn't installed
- QtProgressWindow: preferred path; supports both PySide6 and PyQt6
(interchangeable APIs for our subset)
The factory in ui.py picks Qt → tkinter → headless. Tk stays so the
zipapp still works on bare Python with no extras.
Threading: QApplication runs on the main thread (started by run_with
via QDialog.exec). The restic worker runs on a daemon threading.Thread.
Cross-thread UI updates go via a Signal on a bridge QObject so Qt
auto-marshals them onto the main thread via a queued connection.
Cancellation: WM close + Cancel button both set a flag. sync.pull/push
pass ui.is_cancelled as restic.run's cancel_check; the subprocess gets
killed and returns -1 → exit 1.
Theme: Fusion style + Prism's dark palette (RGB values copied as facts
from PrismLauncher's DarkTheme.cpp). Override with PRISM_THEME=off.
Pyz size went 20 KB → 36 KB (added ui.py + ui_qt.py).
33 tests still green.
This commit is contained in:
+26
-3
@@ -23,25 +23,33 @@ from pathlib import Path
|
||||
from . import restic, scope as scopemod
|
||||
from .cli import Args
|
||||
from .creds import read_credentials
|
||||
from .ui import HeadlessProgress, Progress
|
||||
|
||||
|
||||
def pull(args: Args) -> int:
|
||||
def pull(args: Args, progress: Progress | None = None) -> int:
|
||||
"""Restore latest snapshot's files into pack_folder.
|
||||
|
||||
If the repo has no snapshots yet, this is a no-op (first run on this
|
||||
machine; nothing to restore).
|
||||
"""
|
||||
ui = progress or HeadlessProgress()
|
||||
ui.set_status("Reading credentials…")
|
||||
discord_id, password = read_credentials(args.token_file)
|
||||
|
||||
ui.set_status("Resolving restic binary…")
|
||||
binary = restic.resolve_binary(args)
|
||||
repo = _restic_repo(args.url, discord_id, password)
|
||||
env = _restic_env()
|
||||
|
||||
# Check whether any snapshots exist
|
||||
ui.set_status("Checking remote snapshots…")
|
||||
code, out = restic.run(
|
||||
binary,
|
||||
["-r", repo, "--insecure-no-password", "snapshots", "--json", "--latest", "1"],
|
||||
env=env,
|
||||
cancel_check=ui.is_cancelled,
|
||||
)
|
||||
if code == -1:
|
||||
return 1
|
||||
if code != 0:
|
||||
print(
|
||||
f"cloud-sync: failed to list snapshots (restic exit {code})",
|
||||
@@ -50,6 +58,7 @@ def pull(args: Args) -> int:
|
||||
return 2
|
||||
stripped = out.strip()
|
||||
if stripped in ("", "null", "[]"):
|
||||
ui.set_status("No snapshots yet — nothing to pull")
|
||||
print(
|
||||
"cloud-sync: no snapshots yet for this user "
|
||||
"(first run on this machine?); nothing to pull"
|
||||
@@ -59,6 +68,7 @@ def pull(args: Args) -> int:
|
||||
scope = scopemod.load(args.pack_folder)
|
||||
_, exclude_from = scopemod.materialize_for_restic(args.pack_folder, scope)
|
||||
|
||||
ui.set_status("Restoring files…")
|
||||
code, _ = restic.run(
|
||||
binary,
|
||||
[
|
||||
@@ -68,17 +78,25 @@ def pull(args: Args) -> int:
|
||||
"--exclude-file", str(exclude_from),
|
||||
],
|
||||
env=env,
|
||||
cancel_check=ui.is_cancelled,
|
||||
)
|
||||
if code == -1:
|
||||
return 1
|
||||
if code != 0:
|
||||
print(f"cloud-sync: restic restore failed (exit {code})", file=sys.stderr)
|
||||
return 2
|
||||
ui.set_status("Pull complete")
|
||||
print("cloud-sync: pull ok")
|
||||
return 0
|
||||
|
||||
|
||||
def push(args: Args) -> int:
|
||||
def push(args: Args, progress: Progress | None = None) -> int:
|
||||
"""Snapshot the in-scope files into the user's repo."""
|
||||
ui = progress or HeadlessProgress()
|
||||
ui.set_status("Reading credentials…")
|
||||
discord_id, password = read_credentials(args.token_file)
|
||||
|
||||
ui.set_status("Resolving restic binary…")
|
||||
binary = restic.resolve_binary(args)
|
||||
repo = _restic_repo(args.url, discord_id, password)
|
||||
env = _restic_env()
|
||||
@@ -86,6 +104,7 @@ def push(args: Args) -> int:
|
||||
scope = scopemod.load(args.pack_folder)
|
||||
files_from, exclude_from = scopemod.materialize_for_restic(args.pack_folder, scope)
|
||||
|
||||
ui.set_status("Uploading snapshot…")
|
||||
code, _ = restic.run(
|
||||
binary,
|
||||
[
|
||||
@@ -98,10 +117,14 @@ def push(args: Args) -> int:
|
||||
],
|
||||
env=env,
|
||||
cwd=args.pack_folder,
|
||||
cancel_check=ui.is_cancelled,
|
||||
)
|
||||
if code == -1:
|
||||
return 1
|
||||
if code != 0:
|
||||
print(f"cloud-sync: restic backup failed (exit {code})", file=sys.stderr)
|
||||
return 2
|
||||
ui.set_status("Push complete")
|
||||
print("cloud-sync: push ok")
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user