From d5deef5699aee6907e00e7a99c8b753e18332fa8 Mon Sep 17 00:00:00 2001 From: zyoshoka <107108195+zyoshoka@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:29:24 +0900 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20WebKit=E3=83=96=E3=83=A9?= =?UTF-8?q?=E3=82=A6=E3=82=B6=E3=83=BC=E4=B8=8A=E3=81=A7=E3=82=82=E3=80=8C?= =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E3=81=AE=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E3=82=92=E5=B8=B8=E3=81=AB=E3=82=AA=E3=83=B3=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=80=8D=E6=A9=9F=E8=83=BD=E3=81=8C=E5=8A=B9=E3=81=8F?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20(#12484)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(frontend): WebKitブラウザー上でもkeepScreenOnが効くように * chore: add comment --- packages/frontend/src/boot/common.ts | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/frontend/src/boot/common.ts b/packages/frontend/src/boot/common.ts index 594fe64230..6e216a78b4 100644 --- a/packages/frontend/src/boot/common.ts +++ b/packages/frontend/src/boot/common.ts @@ -202,20 +202,24 @@ export async function common(createVue: () => App) { } }, { immediate: true }); - if (defaultStore.state.keepScreenOn) { - if ('wakeLock' in navigator) { - navigator.wakeLock.request('screen') - .then(() => { - document.addEventListener('visibilitychange', async () => { - if (document.visibilityState === 'visible') { - navigator.wakeLock.request('screen'); - } - }); - }) - .catch(() => { - // If Permission fails on an AppleDevice such as Safari - }); + // Keep screen on + const onVisibilityChange = () => document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible') { + navigator.wakeLock.request('screen'); } + }); + if (defaultStore.state.keepScreenOn && 'wakeLock' in navigator) { + navigator.wakeLock.request('screen') + .then(onVisibilityChange) + .catch(() => { + // On WebKit-based browsers, user activation is required to send wake lock request + // https://webkit.org/blog/13862/the-user-activation-api/ + document.addEventListener( + 'click', + () => navigator.wakeLock.request('screen').then(onVisibilityChange), + { once: true }, + ); + }); } //#region Fetch user