mirror of
https://github.com/dvmarinoff/Auuki.git
synced 2026-02-18 23:41:45 +01:00
* add initial support for storing workouts in indexedDB * update IndexedDB, swipe to reveal delete button * change workout delete button to text, prevent click on swipe * use pointerup to show workout options instead of swipe * center workout info, change arrow btn to options btn * slide workout info with css instead of js * reverse the concat order of default and user added workouts * clarify that iOS is not supported at all * robust wake lock * robust IndexedDB updates
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
import { xf } from './functions.js';
|
|
|
|
class WakeLock {
|
|
constructor(args) {
|
|
this.lock = undefined;
|
|
this.isLocked = false;
|
|
this.isLocable = false;
|
|
this.isVisible = false;
|
|
this.init();
|
|
}
|
|
init() {
|
|
let self = this;
|
|
self.isLocable = ('wakeLock' in navigator);
|
|
self.isVisible = self.checkVisibility();
|
|
|
|
self.lockScreen();
|
|
|
|
document.addEventListener('visibilitychange', self.onVisibilityChange.bind(self));
|
|
|
|
window.addEventListener('beforeunload', e => {
|
|
xf.dispatch('lock:beforeunload');
|
|
});
|
|
}
|
|
checkVisibility() {
|
|
let isVisible = false;
|
|
let visibilityState = document.visibilityState;
|
|
|
|
if(visibilityState === 'visible') {
|
|
isVisible = true;
|
|
} else {
|
|
isVisible = false;
|
|
}
|
|
return isVisible;
|
|
}
|
|
onVisibilityChange () {
|
|
let self = this;
|
|
|
|
if(self.checkVisibility()) {
|
|
self.lockScreen();
|
|
}
|
|
}
|
|
async lockScreen() {
|
|
let self = this;
|
|
if(self.isLocable && self.isVisible) {
|
|
try {
|
|
let lock = await navigator.wakeLock.request('screen');
|
|
self.isLocked = true;
|
|
|
|
lock.addEventListener('release', e => {
|
|
self.isLocked = false;
|
|
xf.dispatch('lock:release');
|
|
console.log(`Wake lock released.`);
|
|
});
|
|
} catch(e) {
|
|
console.warn(`wake-lock: not-supported:`, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const lock = new WakeLock();
|
|
|
|
export { lock };
|