Hwaro::Services::LiveReloadInjectHandler
Inherits HTTP::Handler / Reference / Object
Constants
LIVE_RELOAD_SCRIPT = "<script>\n(function() {\n var reconnectDelay = 1000;\n var maxDelay = 30000;\n var OVERLAY_ID = '__hwaro_build_error__';\n function showError(message) {\n var existing = document.getElementById(OVERLAY_ID);\n if (existing) existing.remove();\n var overlay = document.createElement('div');\n overlay.id = OVERLAY_ID;\n overlay.style.cssText = 'position:fixed;inset:0;z-index:2147483647;background:#fef3c7;color:#78350f;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:14px;line-height:1.55;padding:32px 40px;overflow:auto;box-sizing:border-box;';\n var title = document.createElement('div');\n title.textContent = 'Build failed';\n title.style.cssText = 'font-size:20px;font-weight:600;margin-bottom:16px;color:#92400e;';\n var body = document.createElement('pre');\n body.textContent = message || 'Unknown error';\n body.style.cssText = 'white-space:pre-wrap;margin:0;font-family:inherit;';\n var hint = document.createElement('div');\n hint.textContent = 'hwaro will clear this overlay on the next successful build.';\n hint.style.cssText = 'margin-top:24px;font-size:12px;color:#a16207;';\n overlay.appendChild(title);\n overlay.appendChild(body);\n overlay.appendChild(hint);\n document.body.appendChild(overlay);\n }\n function clearError() {\n var existing = document.getElementById(OVERLAY_ID);\n if (existing) existing.remove();\n }\n function connect() {\n var protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';\n var ws = new WebSocket(protocol + '//' + location.host + '/__hwaro_livereload');\n ws.onopen = function() { reconnectDelay = 1000; };\n ws.onmessage = function(event) {\n var data = event.data;\n if (data === 'reload') {\n clearError();\n location.reload();\n } else if (data === 'clear-error') {\n clearError();\n } else if (typeof data === 'string' && data.indexOf('error:') === 0) {\n try {\n var payload = JSON.parse(data.slice('error:'.length));\n showError(payload && payload.message);\n } catch (e) {\n showError(data.slice('error:'.length));\n }\n }\n };\n ws.onclose = function() {\n setTimeout(function() {\n reconnectDelay = Math.min(reconnectDelay * 2, maxDelay);\n connect();\n }, reconnectDelay);\n };\n }\n connect();\n})();\n</script>"
Client-side script bundle: WebSocket reconnect loop + a
full-screen amber overlay rendered on error:<json> messages.
We render the overlay client-side (not server-side) because a
whole-build failure produces no new HTML to inject into. The
overlay clears on the next reload or clear-error message.
Constructors
new(public_dir : String)
SourceInstance methods
call(context)
Sourceinject_script(html : String) : String
Source