-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
106 lines (99 loc) · 3.6 KB
/
Copy pathindex.html
File metadata and controls
106 lines (99 loc) · 3.6 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LifeTracker</title>
<!-- 防止白色闪烁:隐藏内容 + 加载后显示 -->
<style>
/*
目的:防止 Tauri/React 初始化时出现白屏或未渲染内容的闪烁。
1. 先隐藏 body,避免 WebView/React 加载前出现空白或布局错乱。
2. 媒体查询保证背景色与系统主题一致,防止首帧白屏。
3. React 挂载/内容渲染后再显示 body,实现平滑过渡。
*/
body {
visibility: hidden;
opacity: 0;
transition: opacity 0.2s ease-in-out;
}
/* 兜底:如果JS被禁用,强制显示内容 */
noscript body {
visibility: visible !important;
opacity: 1 !important;
}
/*
初始背景色:根据系统主题自动适配,避免首帧白屏。
需与 Tailwind/ThemeProvider 主题色保持一致。
这样即使 JS 未执行,页面也能正确适配明暗模式。
*/
html, body {
width: 100%;
height: 100%;
margin: 0; /* 移除默认 8px 外边距,避免边缘白条 */
background: #f9fafb; /* 亮色模式下与 Tailwind gray-50 对齐 */
}
@media (prefers-color-scheme: dark) {
html, body {
background: #0f1419; /* 暗色模式下与 ThemeProvider 的 darkBg 对齐 */
}
}
</style>
</head>
<body>
<noscript>
<!-- JavaScript被禁用时的提示 -->
<div style="padding: 20px; text-align: center; font-family: sans-serif;">
<h2>需要启用JavaScript</h2>
<p>LifeTracker需要JavaScript才能正常运行,请启用JavaScript后刷新页面。</p>
</div>
</noscript>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<!--
目的:确保 Tauri/React 初始化完成后再显示内容,避免白屏或未渲染内容的闪烁。
1. MutationObserver 监听 #root 节点内容变化,React 挂载后立即显示 body。
2. 兜底:3 秒后强制显示,防止极端情况下内容迟迟未渲染。
3. 若浏览器不支持 MutationObserver,则 200ms 后兜底显示。
-->
<script>
// 显示应用内容(解除隐藏/透明)
function showApp() {
document.body.style.visibility = 'visible';
document.body.style.opacity = '1';
}
if (window.MutationObserver) {
let hasShown = false;
const observer = new MutationObserver(function(mutations) {
if (hasShown) return;
for (let mutation of mutations) {
if (mutation.addedNodes.length > 0) {
const root = document.getElementById('root');
if (root && root.children.length > 0) {
hasShown = true;
showApp();
observer.disconnect();
return; // 立即退出整个回调函数
}
}
}
});
observer.observe(document.getElementById('root'), {
childList: true,
subtree: true
});
// 兜底:3秒后强制显示,避免无限等待
setTimeout(function() {
if (!hasShown) {
hasShown = true;
showApp();
observer.disconnect();
}
}, 3000);
} else {
// 兜底:如果不支持 MutationObserver,延迟显示
setTimeout(showApp, 200);
}
</script>
</body>
</html>