mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
Added the preload demo experience feature to support presentation mode
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
let workspacePreload: Promise<unknown> | null = null;
|
||||
let adminPreload: Promise<unknown> | null = null;
|
||||
let demoExperiencePreloadStarted = false;
|
||||
|
||||
export function preloadAuthenticatedWorkspace(isAdmin: boolean): Promise<unknown> {
|
||||
if (!workspacePreload) {
|
||||
@@ -25,3 +26,48 @@ export function preloadAuthenticatedWorkspace(isAdmin: boolean): Promise<unknown
|
||||
|
||||
return adminPreload;
|
||||
}
|
||||
|
||||
export function preloadDemoExperience(): () => void {
|
||||
if (demoExperiencePreloadStarted || typeof window === 'undefined') {
|
||||
return () => undefined;
|
||||
}
|
||||
|
||||
demoExperiencePreloadStarted = true;
|
||||
let cancelled = false;
|
||||
let timerId: number | null = null;
|
||||
|
||||
const tasks = [
|
||||
() => import('@/components/VaultPage'),
|
||||
() => import('@/components/SendsPage'),
|
||||
() => import('@/components/TotpCodesPage'),
|
||||
() => import('@/components/SettingsPage'),
|
||||
() => import('@/components/SecurityDevicesPage'),
|
||||
() => import('@/components/AdminPage'),
|
||||
() => import('@/components/BackupCenterPage'),
|
||||
() => import('@/components/ImportPage'),
|
||||
];
|
||||
|
||||
const wait = (ms: number) => new Promise<void>((resolve) => {
|
||||
timerId = window.setTimeout(() => {
|
||||
timerId = null;
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
|
||||
void (async () => {
|
||||
await wait(120);
|
||||
for (const task of tasks) {
|
||||
if (cancelled) return;
|
||||
await task().catch(() => undefined);
|
||||
await wait(180);
|
||||
}
|
||||
})();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (timerId !== null) {
|
||||
window.clearTimeout(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user