Skip to content
src.wesktop.runtime_bridge
Edit
On this page

Host-side native bridge that reloads a pywebview window, clears its web cache, and polls the fastware version endpoint on focus to react to build changes.

#src.wesktop.runtime_bridge

#src.wesktop.runtime_bridge

Host-side native bridge for reacting to fastware build changes.

The PRIMARY update path is page-side: native windows load the same page as the browser, so the framework's /__fastware/client.js reloads the page (over the SSE update channel) when the build id changes -- no host involvement, no polling.

This module is the host-side complement, used mainly for reset flows: it lets the desktop host reload the window, clear the web cache, and -- where pywebview exposes a window focus event -- poll /__fastware/version on focus to detect a changed build id and reload.

Every function takes a duck-typed pywebview window object, so the module is unit-testable with a fake window and imports no pywebview and no GUI.

Build ids have NO ordering: reload happens on a DIFFERENT id, never on a "newer" one.

#reload

python
def reload(window: Any) -> None

Reload the page in window by injecting location.reload().

#clear_web_cache

python
def clear_web_cache(window: Any) -> bool

Best-effort clear of window's web cache.

Uses pywebview's native clear_cache when the installed version exposes it (returns True). Otherwise clears the Cache Storage API from the page via injected JS (returns False -- native API unavailable).

#fetch_build_id

python
def fetch_build_id(version_url: str, *, timeout: float=2.0) -> str | None

GET the fastware version endpoint and return its build_id.

Returns None on any failure (network error, non-JSON body, or a missing/ non-string build_id) -- a probe failure must never crash the host.

#check_and_reload

python
def check_and_reload(window: Any, version_url: str, last_build_id: str | None, *, clear_cache: bool=True, timeout: float=2.0) -> str | None

Probe version_url; reload window if the build id DIFFERS.

Returns the observed build id: the new one on change, otherwise last_build_id; None is never returned on a successful probe. On a probe failure the function returns last_build_id unchanged and does not reload. The first observation (last_build_id is None) records the id without reloading.

#install_focus_poll

python
def install_focus_poll(window: Any, version_url: str, *, on_change: Callable[[str], None] | None=None, initial_build_id: str | None=None, timeout: float=2.0) -> bool

Wire a version poll to window's focus event, if one exists.

On each focus the version endpoint is probed; on a DIFFERENT build id the window is reloaded and on_change is invoked with the new id.

Returns True if a focus event was found and wired, False otherwise. A False result is the documented limitation on pywebview builds without a focus event -- the page-side client.js remains the update path there.

More tools from this site

  • claudestream Drive Claude Code from Python: run it as a subprocess and read its output as typed events, with async and sync sessions, sandbox policies, and tools you define in Python
  • claudewheel A TUI Claude Code Launcher that lets you have more than one profile, manage sessions lifecycle, pick the exact CC version, model to use (even older unlisted ones), pick which GitHub account to use, etc.
  • dirstat Fast, single-binary directory statistics CLI: every file under a tree grouped by format, with counts, sizes, and lines of code, as a colored terminal table or as JSON
  • fastware A batteries-included ASGI framework: msgspec JSON, a managed Granian server, dependency injection, SSE, WebSockets, auth, and a test client
  • go-toml-edit Zero-dep TOML editing library for Go with comment preservation
  • howmuchleft The fastest Claude Code statusline: context window, 5-hour, and weekly limit usage as three customizable gradient bars, rendering in about 6 ms
  • orxtra
  • pgdesign
  • predraw Declarative rendering pipeline: describe a scene in JSON and get SVG, PNG and WebP out, with light and dark style tokens, reusable components and text converted to path outlines
  • reposummary Turn a git repository's history into a Markdown journal: pick a time window or revision range and get a readable digest of what changed, optionally narrated by an LLM
  • rlsbl Release orchestration and project scaffolding CLI that bumps versions, validates a structured JSONL changelog, tags only the commit CI verified, and publishes to npm, PyPI, Go and more
  • safegit git wrapper CLI that gives each commit its own temporary index and retries ref updates on conflict, so concurrent agents share one repository
  • saferm Command-line replacement for rm that archives every deletion with a mandatory reason and the context it ran in, so deleted files can be listed, inspected and restored
  • selfdoc Static Site Generator that builds a project's documentation site directly from its source code, so the docs can never drift from the code they describe, with SEO/AEO, first-class blog, search, and cross-project linking built in
  • strictcli
  • stricttest An always-on test-isolation floor: a pytest plugin and a Go env-hygiene module that make a test suite structurally unable to reach real credentials, the real HOME, the network, or the development repository.
Search