-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
index.html
66 lines (58 loc) · 1.96 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" type="text/css" id="theme-link">
<title>Another Redis Desktop Manager</title>
</head>
<body>
<!-- this script must be placed here after body -->
<script type="text/javascript">
const ipcRenderer = require('electron').ipcRenderer;
function changeCSS(theme = 'light') {
const themeHref = `static/theme/${theme}/index.css`;
document.getElementById('theme-link').href = themeHref;
theme == 'dark' ? document.body.classList.add('dark-mode') :
document.body.classList.remove('dark-mode');
}
function globalChangeTheme(theme) {
ipcRenderer.invoke('changeTheme', theme).then(shouldUseDarkColors => {
// delay to avoid stuck
setTimeout(() => {
changeCSS(shouldUseDarkColors ? 'dark' : 'light');
}, 100);
});
}
// triggered by OS theme changed
ipcRenderer.on('os-theme-updated', (event, arg) => {
// auto change only when theme set to 'system'
if (arg.themeSource != 'system') {
return;
}
setTimeout(() => {
changeCSS(arg.shouldUseDarkColors ? 'dark' : 'light');
}, 100);
});
// theme init at startup
(() => {
let theme = localStorage.theme;
if (!['system', 'light', 'dark'].includes(theme)) {
theme = 'system';
}
// follow system OS
if (theme == 'system') {
const dark = (new URL(window.location.href)).searchParams.get('dark');
changeCSS(dark === 'true' ? 'dark' : 'light');
}
// setted light or dark
else {
changeCSS(theme);
ipcRenderer.invoke('changeTheme', theme);
}
})();
</script>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>