feat(web): add wake lock when uploading assets (#29820)

This commit is contained in:
Diogo Correia
2026-07-16 12:41:37 +02:00
committed by GitHub
parent 26e07548a7
commit c50a807bc1
2 changed files with 61 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import { on } from 'svelte/events';
import { browser } from '$app/environment';
const isSupported = browser && 'wakeLock' in navigator;
let sentinel: WakeLockSentinel | undefined;
let acquiring = false;
export async function acquireWakeLock() {
if (!isSupported) {
return;
}
// eslint-disable-next-line tscompat/tscompat
if (sentinel && !sentinel.released) {
return;
}
if (acquiring) {
return;
}
acquiring = true;
try {
// eslint-disable-next-line tscompat/tscompat
sentinel = await navigator.wakeLock.request('screen');
} catch (error) {
console.warn('Failed to acquire wake lock:', error);
} finally {
acquiring = false;
}
}
export async function releaseWakeLock() {
if (sentinel) {
const toReleaseSentinel = sentinel;
// Unset first to avoid race condition after await
sentinel = undefined;
// eslint-disable-next-line tscompat/tscompat
await toReleaseSentinel.release();
}
}
if (isSupported) {
// Wake lock is cleared when user changes to a different tab,
// so we need to reacquire the wake lock when they come back.
on(globalThis, 'visibilitychange', () => {
if (sentinel && document.visibilityState === 'visible') {
void acquireWakeLock();
}
});
}
+11
View File
@@ -2,6 +2,7 @@
import { locale } from '$lib/stores/preferences.store';
import { uploadAssetsStore } from '$lib/stores/upload';
import { uploadExecutionQueue } from '$lib/utils/file-uploader';
import { acquireWakeLock, releaseWakeLock } from '$lib/utils/wakelock.svelte';
import { Icon, IconButton, toastManager } from '@immich/ui';
import { mdiCancel, mdiCloudUploadOutline, mdiCog, mdiWindowMinimize } from '@mdi/js';
import { t } from 'svelte-i18n';
@@ -15,11 +16,21 @@
let { stats, isDismissible, isUploading, remainingUploads } = uploadAssetsStore;
let hasRemaining = $derived($remainingUploads > 0);
$effect(() => {
if ($isUploading) {
showDetail = true;
}
});
$effect(() => {
if (hasRemaining) {
void acquireWakeLock();
} else {
void releaseWakeLock();
}
});
</script>
{#if $isUploading}