Skip to content

Commit 3f21cde

Browse files
committed
Add theming support to error page
1 parent 6f675d9 commit 3f21cde

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

special-pages/pages/errorpage/public/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55
<meta name="viewport"
66
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<script>
9+
// $BG_COLOR$ is replaced by native via string interpolation.
10+
// This script must be in <head> to block rendering and prevent flash of wrong color.
11+
const bgColor = "$BG_COLOR$";
12+
const hasBgColor = !!bgColor && !bgColor.startsWith("$");
13+
if (hasBgColor) {
14+
document.documentElement.style.background = bgColor;
15+
}
16+
17+
/**
18+
* Called by native to update the page theme
19+
* @param {{ bgColor: string }} payload - Object containing the new background color
20+
*/
21+
window.onChangeTheme = function(payload) {
22+
if (payload && payload.bgColor) {
23+
document.body.style.background = payload.bgColor;
24+
}
25+
};
26+
</script>
827
<link rel="stylesheet" href="style.css">
928
</head>
1029
<body>

special-pages/pages/errorpage/readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ So far, the following platforms are supported
1010

1111
- macOS
1212

13+
### Theming
14+
15+
The error page supports theming through two mechanisms:
16+
17+
#### Template Variable: `$BG_COLOR$`
18+
Native performs string interpolation to replace `$BG_COLOR$` with a valid CSS color value (e.g., `#ffffff`, `rgb(51, 51, 51)`). This sets the initial background color to prevent a flash of wrong color while the page loads.
19+
20+
If string interpolation is not performed (i.e., `$BG_COLOR$` is left as-is), the page falls back to the default CSS background colors defined in `style.css`.
21+
22+
#### Callback: `window.onChangeTheme`
23+
Native can call `window.onChangeTheme(payload)` to update the theme at runtime.
24+
25+
**Payload:**
26+
```json
27+
{
28+
"bgColor": "#ff0000"
29+
}
30+
```
31+
32+
**Example native usage:**
33+
```javascript
34+
window.onChangeTheme({ bgColor: '#333333' });
35+
```
36+
1337
---
1438

1539
## Contributing

0 commit comments

Comments
 (0)