Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Restore web app loading screen quotes and add percentage load check
Leendert de Borstf00d51d9578d
diff --git a/apps/web/index.html b/apps/web/index.htmlindex f39634a0d..1f01fdd11 100644--- a/apps/web/index.html+++ b/apps/web/index.html@@ -85,6 +85,7 @@</div><h2 id="loading-title" class="mt-4 text-xl font-semibold text-gray-900 dark:text-white">AliasVault is loading</h2><p id="loading-message" class="mt-2 text-sm text-gray-500 dark:text-gray-400">Initializing secure environment. AliasVault prioritizes your privacy by running entirely in your browser. The first load might take a short while.</p>+ <div id="loading-progress-text" class="text-sm font-medium text-gray-700 dark:text-gray-300 mt-4"></div><div class="mt-4 text-center"><p id="security-quote" class="text-sm text-primary-600 italic"></p></div>@@ -133,13 +134,36 @@var text = getTranslation(entry.key);if (element && text) { element.textContent = text; }});- var securityQuotes = getTranslation('quotes.security');- if (securityQuotes && securityQuotes.length > 0) {+ var quoteSource = getTranslation('quotes.security') || {};+ var securityQuotes = Array.isArray(quoteSource) ? quoteSource : Object.keys(quoteSource).map(function (key) { return quoteSource[key]; });+ if (securityQuotes.length > 0) {var quoteElement = document.getElementById('security-quote');var randomIndex = Math.floor(Math.random() * securityQuotes.length);if (quoteElement) { quoteElement.textContent = '"' + securityQuotes[randomIndex] + '"'; }}}+ var minDisplayTime = 400;+ (function () {+ var progressElement = document.getElementById('loading-progress-text');+ var downloadPercent = 0;+ var hasProgress = false;+ function render() {+ var timePercent = Math.min(100, performance.now() / minDisplayTime * 100);+ var shown = Math.floor(Math.min(downloadPercent, timePercent));+ progressElement.textContent = shown + '%';+ if (shown < 100) { requestAnimationFrame(render); }+ }+ function onProgress(loaded, total) {+ if (!progressElement || !total) { return; }+ downloadPercent = Math.min(100, loaded / total * 100);+ if (!hasProgress) {+ hasProgress = true;+ requestAnimationFrame(render);+ }+ }+ window.__onLoadingProgress = onProgress;+ if (window.__loadingProgress) { onProgress(window.__loadingProgress.loaded, window.__loadingProgress.total); }+ })();var loadingScreen = document.getElementById('loading-screen');var errorMessageElement = document.getElementById('error-message');var refreshButton = document.getElementById('refresh-button');@@ -162,7 +186,6 @@}function manageLoadingScreen() {var startTime = new Date().getTime();- var minDisplayTime = 500;var checkInterval = 200;var refreshButtonTimeout = 20000;var appElement = document.getElementById('app');diff --git a/apps/web/src/platform/WebPlatform.ts b/apps/web/src/platform/WebPlatform.tsindex 3cadcab40..b4f30248e 100644--- a/apps/web/src/platform/WebPlatform.ts+++ b/apps/web/src/platform/WebPlatform.ts@@ -20,10 +20,14 @@ const TRANSLATION_KEYS: Record<TranslatableMessage, string> = {};/**- * The Rust core, streamed into WebAssembly.instantiateStreaming; it also hosts the SQLite engine. The wasm URL is- * content hashed by Vite, so a new build never loads a cached binary from an older release.+ * The Rust core, streamed into WebAssembly.instantiateStreaming; it also hosts the SQLite engine.*/-const rustCore = createWasmRustCore(async (): Promise<Response> => fetch(wasmUrl));+const rustCore = createWasmRustCore(async (): Promise<Response> => {+ const host = window as { __aliasvaultCoreWasm?: Promise<Response> };+ const early = host.__aliasvaultCoreWasm;+ host.__aliasvaultCoreWasm = undefined;+ return early ? early.catch(() => fetch(wasmUrl)) : fetch(wasmUrl);+});/*** The platform the web app registers with the client core.diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.tsindex 0bb2d62cb..9d3bc9600 100644--- a/apps/web/vite.config.ts+++ b/apps/web/vite.config.ts@@ -1,4 +1,4 @@-import { readdirSync, readFileSync } from 'node:fs';+import { readdirSync, readFileSync, statSync } from 'node:fs';import path from 'node:path';import react from '@vitejs/plugin-react';@@ -33,22 +33,60 @@ function loadingScreenLocales(): Plugin {}/**- * Preload the content hashed Rust core wasm from index.html, so its download runs in parallel with the app bundle.+ * Add loading progress tracking to index.html, showing a percentage of the download as indicator on the loading screen.*/-function preloadCoreWasm(): Plugin {+function loadingProgress(): Plugin {return {- name: 'preload-core-wasm',- apply: 'build',+ name: 'loading-progress',transformIndexHtml(_html, context) {- const wasm = Object.values(context.bundle ?? {}).find((chunk) => chunk.type === 'asset' && /aliasvault_core_bg-.*\.wasm$/.test(chunk.fileName));- if (!wasm) {- throw new Error('The Rust core wasm asset is missing from the bundle.');+ if (!context.bundle) {+ const wasmFile = path.join(CORE_DIR, 'client/wasm/aliasvault_core_bg.wasm');+ const devAssets = [{ url: `/@fs${wasmFile}`, size: statSync(wasmFile).size, wasm: true }];+ return [{ tag: 'script', children: `window.__loadingAssets=${JSON.stringify(devAssets)};${EARLY_LOAD_SCRIPT}`, injectTo: 'head-prepend' }];}- return [{ tag: 'link', attrs: { rel: 'preload', href: `/${wasm.fileName}`, as: 'fetch', type: 'application/wasm', crossorigin: 'anonymous' }, injectTo: 'head' }];+ const bundle = Object.values(context.bundle);+ const wasm = bundle.find((item) => item.type === 'asset' && /aliasvault_core_bg-.*\.wasm$/.test(item.fileName));+ const entry = bundle.find((item) => item.type === 'chunk' && item.isEntry);+ if (!wasm || wasm.type !== 'asset' || !entry || entry.type !== 'chunk') {+ throw new Error('The entry chunk or the Rust core wasm asset is missing from the bundle.');+ }+ const sizeOf = (fileName: string): number => {+ const item = context.bundle?.[fileName];+ if (!item) {+ return 0;+ }+ return item.type === 'chunk' ? Buffer.byteLength(item.code) : typeof item.source === 'string' ? Buffer.byteLength(item.source) : item.source.byteLength;+ };+ const files = [entry.fileName, ...entry.imports, ...(entry.viteMetadata?.importedCss ?? [])];+ const assets: { url: string; size: number; wasm?: boolean }[] = [...new Set(files)].map((fileName) => ({ url: `/${fileName}`, size: sizeOf(fileName) }));+ assets.push({ url: `/${wasm.fileName}`, size: sizeOf(wasm.fileName), wasm: true });+ return [{ tag: 'script', children: `window.__loadingAssets=${JSON.stringify(assets)};${EARLY_LOAD_SCRIPT}`, injectTo: 'head-prepend' }];},};}+/*+ * Runs in the head of index.html: downloads the wasm while counting bytes, and counts the other files once the browser+ * reports them as loaded.+ */+const EARLY_LOAD_SCRIPT = `(function(){+var assets=window.__loadingAssets,loaded={},total=0;+assets.forEach(function(a){total+=a.size;});+function report(){var done=0;assets.forEach(function(a){done+=Math.min(loaded[a.url]||0,a.size);});window.__loadingProgress={loaded:done,total:total};if(window.__onLoadingProgress){window.__onLoadingProgress(done,total);}}+var wasm=assets.filter(function(a){return a.wasm;})[0];+if(wasm&&window.fetch&&window.ReadableStream){+window.__aliasvaultCoreWasm=fetch(wasm.url).then(function(response){+if(!response.ok||!response.body){return response;}+var reader=response.body.getReader(),chunks=[];+function pump(){return reader.read().then(function(r){+if(r.done){loaded[wasm.url]=wasm.size;report();return new Response(new Blob(chunks),{status:response.status,headers:{'Content-Type':'application/wasm'}});}+chunks.push(r.value);loaded[wasm.url]=(loaded[wasm.url]||0)+r.value.byteLength;report();return pump();});}+return pump();});+}+if(window.PerformanceObserver){try{new PerformanceObserver(function(list){list.getEntries().forEach(function(e){var p;try{p=new URL(e.name).pathname;}catch(x){return;}assets.forEach(function(a){if(!a.wasm&&a.url===p){loaded[a.url]=a.size;}});});report();}).observe({type:'resource',buffered:true});}catch(x){}}+report();+})();`;+/*** Minify index.html (markup, inline scripts and styles) as the last transform, keeping only the header comment.*/@@ -97,7 +135,7 @@ export default defineConfig({plugins: [react(),loadingScreenLocales(),- preloadCoreWasm(),+ loadingProgress(),minifyIndexHtml(),],});