Files
WatermarkRemover-AI/scripts/check_webview.py
D-Ogi ae98ac0e10 Replace IOPaint with a verified standalone LaMA runtime (#88)
Replace the IOPaint dependency with a small verified TorchScript LaMA adapter, shared dependency manifests, reliable model preparation, and cross-platform application validation.

Preserve crop/pad/composite behavior while handling empty masks and tiny inputs safely. Add integrity, offline, installer, image/video, and desktop backend coverage.

Closes #48. Closes #49.
2026-09-16 07:07:04 +02:00

56 lines
1.5 KiB
Python

"""Check that the installed desktop backend can call Python from JavaScript."""
import os
import threading
import time
import webview
class Bridge:
"""Minimal API used only by this installation check."""
def ping(self):
"""Return a value for the browser to expose after resolving its API call."""
return "bridge-ok"
completed = threading.Event()
finished = threading.Event()
window = webview.create_window(
"Backend verification",
html="""<html><body><script>
window.addEventListener('pywebviewready', async () => {
window.bridgeResult = await window.pywebview.api.ping();
});
</script></body></html>""",
js_api=Bridge(),
hidden=True,
)
def check_bridge():
"""Close only after the browser has received its Python API response."""
deadline = time.monotonic() + 45
while time.monotonic() < deadline:
if window.evaluate_js("window.bridgeResult || null") == "bridge-ok":
completed.set()
break
time.sleep(0.1)
window.destroy()
def watchdog():
"""Fail even if startup, a native JS call or window teardown hangs."""
if not finished.wait(60):
print("Backend bridge/startup/teardown timed out", flush=True)
os._exit(1)
threading.Thread(target=watchdog, daemon=True).start()
webview.start(check_bridge)
finished.set()
if not completed.is_set():
raise SystemExit("Backend closed before completing its bridge check")
print("Desktop backend JavaScript/Python bridge passed")