forked from mirror/misskey
fix(frontend): WebKitブラウザー上でも「デバイスの画面を常にオンにする」機能が効くように (#12484)
* fix(frontend): WebKitブラウザー上でもkeepScreenOnが効くように * chore: add comment
This commit is contained in:
parent
4e882414b2
commit
d5deef5699
@ -202,20 +202,24 @@ export async function common(createVue: () => App<Element>) {
|
|||||||
}
|
}
|
||||||
}, { immediate: true });
|
}, { immediate: true });
|
||||||
|
|
||||||
if (defaultStore.state.keepScreenOn) {
|
// Keep screen on
|
||||||
if ('wakeLock' in navigator) {
|
const onVisibilityChange = () => document.addEventListener('visibilitychange', () => {
|
||||||
navigator.wakeLock.request('screen')
|
if (document.visibilityState === 'visible') {
|
||||||
.then(() => {
|
navigator.wakeLock.request('screen');
|
||||||
document.addEventListener('visibilitychange', async () => {
|
|
||||||
if (document.visibilityState === 'visible') {
|
|
||||||
navigator.wakeLock.request('screen');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
// If Permission fails on an AppleDevice such as Safari
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
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
|
//#region Fetch user
|
||||||
|
Loading…
Reference in New Issue
Block a user