Repository navigation
Expand file tree
/
Copy pathboot.html
More file actions
240 lines (231 loc) · 12.3 KB
/
Copy pathboot.html
File metadata and controls
240 lines (231 loc) · 12.3 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#000000">
<style>
:root { color-scheme: dark; font-family: "Segoe UI", system-ui, sans-serif; }
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: #f5f6fa; background: #000; }
main { position: fixed; inset: 0; text-align: center; }
#bootLogo {
position: absolute; top: 50%; left: 50%;
width: min(24vw, 144px); height: min(24vw, 144px);
max-width: calc(100vw - 48px); max-height: calc(100vh - 48px);
object-fit: contain; transform: translate(-50%, -50%);
animation: logoAppear .8s cubic-bezier(.2,.8,.2,1) both;
}
#status {
display: none; position: absolute; left: 50%; bottom: 28px;
width: min(600px, calc(100vw - 48px)); transform: translateX(-50%);
margin: 0; color: #ffb4ab; font-size: 12px; overflow-wrap: anywhere;
}
#bootLogs {
display: none; position: absolute; left: 24px; bottom: 24px;
width: min(560px, calc(100vw - 48px)); max-height: 28vh; overflow: hidden;
color: rgba(237, 242, 255, .72); font: 11px/1.55 Consolas, "Cascadia Mono", monospace;
text-align: left; text-shadow: 0 1px 3px #000; pointer-events: none;
}
.boot-log { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boot-log::before { color: #7de0a3; content: "[ OK ] "; }
.boot-log.error { color: #ffb4ab; }
.boot-log.error::before { color: #ff6b6b; content: "[ FAIL ] "; }
@keyframes logoAppear { from { opacity: 0; translate: 0 8px; scale: .96; } to { opacity: 1; translate: 0 0; scale: 1; } }
/* Installing an update (boot.html?update=1): a progress bar under the logo, then "Rebooting…". */
#install { display: none; position: absolute; left: 50%; top: auto; bottom: max(64px, 9vh); width: min(240px, 60vw); transform: translateX(-50%); }
body.updating #install { display: block; animation: logoAppear .8s cubic-bezier(.2,.8,.2,1) .15s both; }
.ins-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .2); overflow: hidden; transition: opacity .35s ease; }
.ins-fill { width: 0; height: 100%; border-radius: inherit; background: #f5f6fa; transition: width .7s cubic-bezier(.3, .7, .3, 1); }
.ins-text { margin-top: 14px; min-height: 1.4em; color: rgba(245, 246, 250, .6); font-size: 12.5px; transition: opacity .25s ease; }
#install.rebooting .ins-track { opacity: 0; }
#install.rebooting .ins-text { margin-top: -12px; color: #f5f6fa; font-size: 14px; }
#install.failed .ins-text { color: #ffb4ab; }
/* Boot animation (Settings › Functions Lab › Boot animation), passed as ?anim= by the launcher. */
body[data-anim="zoom"] #bootLogo { animation: logoZoom .9s cubic-bezier(.2, 0, 0, 1) both; }
@keyframes logoZoom { from { opacity: 0; scale: 1.6; filter: blur(10px); } 70% { opacity: 1; filter: blur(0); } to { opacity: 1; scale: 1; } }
body[data-anim="pulse"] #bootLogo { animation: logoAppear .8s cubic-bezier(.2,.8,.2,1) both, logoPulse 2.2s .8s ease-in-out infinite; }
@keyframes logoPulse { 50% { scale: 1.07; filter: drop-shadow(0 0 22px rgba(120, 170, 255, .75)); } }
#bootOrbit { display: none; position: absolute; top: 50%; left: 50%; width: min(40vw, 230px); height: min(40vw, 230px); translate: -50% -50%; animation: orbitSpin 1.6s linear infinite; }
body[data-anim="orbit"] #bootOrbit { display: block; }
#bootOrbit i { position: absolute; top: 0; left: 50%; width: 9px; height: 9px; margin-left: -4.5px; border-radius: 50%; background: #fff; box-shadow: 0 0 12px #8fb8ff;
transform-origin: 4.5px min(20vw, 115px); }
#bootOrbit i:nth-child(2) { rotate: -28deg; opacity: .6; } #bootOrbit i:nth-child(3) { rotate: -56deg; opacity: .3; }
@keyframes orbitSpin { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) {
#bootLogo, body[data-anim] #bootLogo, #bootOrbit { animation: none; }
}
</style>
</head>
<body>
<main role="status" aria-live="polite">
<div id="bootOrbit" aria-hidden="true"><i></i><i></i><i></i></div>
<img id="bootLogo" src="desktop/assets/icons/stars.png" alt="">
<div id="install"><div class="ins-track"><div class="ins-fill"></div></div><div class="ins-text"></div></div>
<p id="status"></p>
<div id="bootLogs" aria-hidden="true"></div>
</main>
<script>
const statusLabel = document.getElementById('status');
const bootLogo = document.getElementById('bootLogo');
const bootLogs = document.getElementById('bootLogs');
// The launcher shows this page from disk (file://) while the kernel is still starting. No API can answer
// yet, so there it only plays the intro and the launcher replaces it as soon as the kernel is ready:
// a normal start must not look like an error.
const startedFromDisk = location.protocol === 'file:';
let verboseBoot = new URLSearchParams(location.search).get('verbose') === '1';
const bootAnimation = new URLSearchParams(location.search).get('anim');
if (['zoom', 'pulse', 'orbit'].includes(bootAnimation)) document.body.dataset.anim = bootAnimation;
if (verboseBoot) bootLogs.style.display = 'block';
function logBoot(message, isError = false) {
if (!verboseBoot) return;
const line = document.createElement('div');
line.className = isError ? 'boot-log error' : 'boot-log';
line.textContent = `${new Date().toLocaleTimeString()} ${message}`;
bootLogs.append(line);
while (bootLogs.childElementCount > 8) bootLogs.firstElementChild.remove();
}
function preloadImage(source, timeoutMs = 5000) {
return new Promise(resolve => {
const image = new Image();
let finished = false;
let decodeFallbackTimer = null;
const finish = success => {
if (finished) return;
finished = true;
clearTimeout(timer);
clearTimeout(decodeFallbackTimer);
resolve(success);
};
const timer = setTimeout(() => finish(false), timeoutMs);
image.onload = () => {
if (!image.naturalWidth) {
finish(false);
return;
}
if (typeof image.decode === 'function') {
decodeFallbackTimer = setTimeout(() => finish(image.complete && image.naturalWidth > 0), 700);
image.decode().then(() => finish(true)).catch(() => finish(image.complete && image.naturalWidth > 0));
} else {
finish(true);
}
};
image.onerror = () => finish(false);
image.src = source;
if (image.complete && image.naturalWidth > 0) finish(true);
});
}
function getActiveWallpaper() {
const stored = localStorage.getItem('wallpaper');
if (!stored) return null;
try {
const base = stored.startsWith('../')
? `${location.origin}/desktop/apps/settings/assets/`
: location.href;
const resolved = new URL(stored, base);
return ['http:', 'https:', 'data:', 'blob:'].includes(resolved.protocol) ? resolved.href : null;
} catch {
return null;
}
}
async function start() {
if (startedFromDisk) {
// Only a start that really drags on gets a message, and it is not an error.
setTimeout(() => {
statusLabel.textContent = 'Starting hyadeOS is taking longer than usual…';
statusLabel.style.display = 'block';
}, 30000);
return;
}
let failures = 0;
while (true) {
try {
logBoot('Waiting for system services');
const response = await fetch('/api/system/boot-assets', { cache: 'no-store' });
if (!response.ok) throw new Error(`asset list request failed (${response.status})`);
const assets = await response.json();
if (typeof assets.requiredWallpaper !== 'string' || !Array.isArray(assets.icons) || !Array.isArray(assets.optionalAssets)) {
throw new Error('E: boot_assetlist_incomplete');
}
if (typeof assets.bootLogo !== 'string') throw new Error('E: boot_logo_settings_not_available');
verboseBoot ||= assets.verbose === true;
if (verboseBoot) bootLogs.style.display = 'block';
logBoot('system services are ready');
logBoot('booting assets manifest loaded');
const selectedBootLogo = assets.bootLogo;
if (await preloadImage(selectedBootLogo, 8000)) {
bootLogo.src = selectedBootLogo;
logBoot(selectedBootLogo.includes('bootlogo.user') ? 'mwos_bootscreen started' : 'mwos_default_bootscreen started');
} else if (selectedBootLogo !== '/desktop/assets/icons/stars.png') {
bootLogo.src = '/desktop/assets/icons/stars.png';
if (!await preloadImage(bootLogo.src, 8000)) throw new Error('Neither the custom nor default boot logo could be decoded');
logBoot('E: boot_logo_not_decoded');
} else {
throw new Error('E: boot_logo_not_decoded');
}
const activeWallpaper = getActiveWallpaper();
const sources = [...assets.optionalAssets, ...assets.icons];
if (activeWallpaper) sources.unshift(activeWallpaper);
const uniqueSources = [...new Set([assets.requiredWallpaper, ...sources])];
if (!await preloadImage(assets.requiredWallpaper, 15000)) {
throw new Error('E: wallpaper_not_decoded');
}
logBoot('wallpaper_service started');
const optional = uniqueSources.slice(1);
const wallpaperSources = optional.filter(source => /wallpaper/i.test(source));
const otherSources = optional.filter(source => !/wallpaper/i.test(source));
for (const source of wallpaperSources) {
if (await preloadImage(source, 8000)) logBoot(`wallpaper ready: ${new URL(source, location.href).pathname.split('/').pop()}`);
}
for (let index = 0; index < otherSources.length; index += 6) {
const batch = otherSources.slice(index, index + 6);
const results = await Promise.all(batch.map(source => preloadImage(source)));
const loadedCount = results.filter(Boolean).length;
const batchLabel = `${Math.min(index + batch.length, otherSources.length)}/${otherSources.length}`;
logBoot(loadedCount === batch.length
? `Interface images decoded: ${batchLabel}`
: `Interface images decoded: ${batchLabel} (${batch.length - loadedCount} unavailable)`);
}
logBoot('startup complete; opening desktop');
location.replace('/');
return;
} catch (error) {
failures += 1;
logBoot(`E: boot failed: ${error.message}`, true);
// The first misses are normal (the kernel is still waking up): show the error only if it persists.
if (failures >= 3) {
statusLabel.textContent = `E: could not finish booting: ${error.message}. retrying…`;
statusLabel.style.display = 'block';
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
}
}
// Installing an update: the launcher feeds the installer's progress to hyadeOSInstall().
if (new URLSearchParams(location.search).get('update') === '1') {
document.body.classList.add('updating');
const box = document.getElementById('install');
const fill = box.querySelector('.ins-fill'), text = box.querySelector('.ins-text');
let shown = 0;
text.textContent = 'Preparing to install…';
window.hyadeOSInstall = state => {
if (state.rebooting) {
const reboot = () => {
box.classList.add('rebooting');
box.classList.toggle('failed', !!state.error);
text.textContent = state.error ? 'The update could not be installed. Restarting…' : 'Rebooting…';
};
// The bar reaches the end before it gives way.
if (state.error) reboot(); else { fill.style.width = '100%'; setTimeout(reboot, 700); }
return;
}
if (typeof state.percent === 'number') { shown = Math.max(shown, Math.min(100, state.percent)); fill.style.width = shown + '%'; }
text.textContent = state.version ? `Installing hyadeOS ${state.version}…` : 'Installing update…';
};
} else {
start();
}
</script>
</body>
</html>