#!/usr/bin/env python3 """Patch Stockholm bridge JS files to use window.__stockholmBase for API paths. Usage: patch-stockholm-bridge.py [ ...] Applied once by `make prepare-stockholm`. Idempotent — already-patched files are left unchanged. """ import sys REPLACEMENTS = [ ( 'xhr.open("POST", "/api/native/appSend"', 'xhr.open("POST", (window.__stockholmBase||"") + "/api/native/appSend"', ), ( 'xhr.open("GET", "/api/native/runQueue', 'xhr.open("GET", (window.__stockholmBase||"") + "/api/native/runQueue', ), ( 'var proxyPath = "/api/http-proxy";', 'var proxyPath = (window.__stockholmBase||"") + "/api/http-proxy";', ), ( # The standalone /api/http-proxy declaration in browser_http_proxy.js # uses an UPPERCASE constant name. Same shape as above, different # identifier — keep both replacements; the lowercase one applies to # app_comm.js, the uppercase one to browser_http_proxy.js. 'var PROXY_PATH = "/api/http-proxy";', 'var PROXY_PATH = (window.__stockholmBase||"") + "/api/http-proxy";', ), ( # browser_http_proxy.js's IIFE evaluates PROXY_PATH at script-load # time, but the injected bootstrap that defines window.__stockholmBase # is placed just before — i.e. after the