Files
librechat-custom/patch_index.py
T
inference-admin 046e97b024 pwa: drop manifest theme_color so Firefox chrome follows the phone theme
Firefox for Android ignores meta theme-color entirely; its PWA window takes
toolbar/status from manifest theme_color and the navigation bar (white/black)
from background_color, so the cream value framed the dark app with light bands.
With theme_color absent Firefox falls back to its own light/dark chrome.
Chromium keeps the per-scheme meta tags and custom2.js sync.
2026-11-28 17:05:07 +00:00

106 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""Inject co-op branding + a per-build marker into the built index.html.
Non-fatal by design: if the file is missing or upstream changes shape, we
exit 0 so a cosmetic patch can never break a version bump.
The x-coop-build marker makes index.html unique per build, which changes the
service worker's precache revision — otherwise stale clients keep running the
old cached app shell (the "my changes never deploy" class of bug).
"""
import time
PATH = "/app/code/librechat/client/dist/index.html"
try:
html = open(PATH, encoding="utf-8").read()
except OSError:
raise SystemExit(0)
# 1. Title
html = html.replace("<title>LibreChat</title>", "<title>Inference Co\u2011op</title>")
# 2. Stylesheet + helper script (idempotent — skip if already present)
if "assets/custom.css" not in html:
html = html.replace(
"</title>",
'</title>\n <link rel="stylesheet" href="assets/custom.css">',
1,
)
if "assets/custom2.js" not in html:
html = html.replace(
'<link rel="stylesheet" href="assets/custom.css">',
'<link rel="stylesheet" href="assets/custom.css">\n <script src="assets/custom2.js"></script>',
1,
)
# 3. Per-build marker → forces the service worker to refresh the precache
if "x-coop-build" not in html:
marker = '<meta name="x-coop-build" content="{}">'.format(int(time.time()))
html = html.replace("</title>", "</title>\n " + marker, 1)
# 3b. PWA chrome: let the page draw under system bars (Android 15 edge-to-edge,
# display cutouts, iOS safe areas). The page background is theme-correct
# (custom.css), so the top/bottom bands match the app theme; safe-area
# padding in custom.css keeps content clear of the bars. Also drop
# crossorigin="use-credentials" from the manifest link — Firefox Android
# fails to resolve manifest icons on credentialed fetches (blank/missing
# launcher icon).
html = html.replace(
"initial-scale=1, interactive-widget=resizes-content",
"initial-scale=1, interactive-widget=resizes-content, viewport-fit=cover",
)
html = html.replace(
'<link rel="manifest" href="./manifest.webmanifest" crossorigin="use-credentials">',
'<link rel="manifest" href="./manifest.webmanifest">',
)
open(PATH, "w", encoding="utf-8").write(html)
# 4. Web manifest identity: co-op name + a 512 icon installable as "any".
# (theme_color/background_color are fixed by the later Dockerfile sed.)
MPATH = "/app/code/librechat/client/dist/manifest.webmanifest"
try:
import json as _json
mf = _json.load(open(MPATH, encoding="utf-8"))
mf["name"] = "Inference Co\u2011op"
mf["short_name"] = "Inference"
mf["description"] = "Member-governed AI inference \u2014 private and renewable model choices."
# NO theme_color. Firefox for Android never implemented <meta name=theme-color>
# (the custom2.js sync therefore only reaches Chromium), and its PWA window
# takes the chrome colours from the manifest alone:
# android-components feature/pwa/ext/WebAppManifest.kt: toCustomTabConfig()
# sets toolbarColor = themeColor and navigationBarColor = WHITE/BLACK
# derived from background_color, but only when BOTH are present.
# A cream theme_color therefore paints a cream status/toolbar band and a
# pure-white navigation bar around the dark app, with no runtime override
# possible. With theme_color absent the config is null and Firefox uses its
# own light/dark toolbar surface, which follows the phone theme.
# Chromium still gets the per-scheme meta tags from the Dockerfile.
# background_color stays cream: Chrome's splash screen uses it.
mf.pop("theme_color", None)
# Deterministic icon list: explicit any/maskable entries (no dual-purpose
# values — some Firefox Android versions mishandle "any maskable"), and
# the launcher-suitable sizes first. Each src carries a per-build version
# query: PWA icon URLs are served with max-age=172800, and removing/re-adding
# the PWA does NOT clear the phone's HTTP cache — without the query, launchers
# keep rendering the PREVIOUS build's icon bytes ("my icon never changes").
ver = str(int(time.time()))
def _v(src: str) -> str:
return f"{src}?v={ver}"
mf["icons"] = [
{"src": _v("assets/icon-192x192.png"), "sizes": "192x192", "type": "image/png", "purpose": "any"},
{"src": _v("assets/maskable-icon.png"), "sizes": "512x512", "type": "image/png", "purpose": "any"},
{"src": _v("assets/maskable-icon.png"), "sizes": "512x512", "type": "image/png", "purpose": "maskable"},
{"src": _v("assets/apple-touch-icon-180x180.png"), "sizes": "180x180", "type": "image/png"},
{"src": _v("assets/favicon-32x32.png"), "sizes": "32x32", "type": "image/png"},
{"src": _v("assets/favicon-16x16.png"), "sizes": "16x16", "type": "image/png"},
]
open(MPATH, "w", encoding="utf-8").write(_json.dumps(mf, indent=2))
print("manifest: co-op identity set")
except OSError:
raise SystemExit(0)
print("index.html: co-op branding + build marker injected")