dyomedea/src/index.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-25 15:45:26 +00:00
/* @refresh reload */
2022-11-25 15:33:59 +00:00
import { render } from 'solid-js/web';
2022-11-25 15:45:26 +00:00
import { Router, hashIntegration } from '@solidjs/router';
2022-11-25 15:45:26 +00:00
import App from './App';
2022-11-27 21:50:47 +00:00
// See https://stackoverflow.com/questions/71538643/property-wakelock-does-not-exist-on-type-navigator
const requestWakeLock = async () => {
const anyNav: any = navigator;
if ('wakeLock' in navigator) {
try {
const wakeLock = await anyNav['wakeLock'].request('screen');
} catch (err: any) {
// The wake lock request fails - usually system-related, such as low battery.
console.log(`Wake lock request failed: ${err.name}, ${err.message}`);
}
} else {
console.log('No wake lock support here...');
}
};
const handleVisibilityChange = () => {
if (document.hidden) {
console.log('Application hidden');
} else {
console.log('Application visible');
requestWakeLock();
}
};
// See https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
document.addEventListener('visibilitychange', handleVisibilityChange, false);
2022-11-27 21:50:47 +00:00
requestWakeLock();
2022-11-25 15:45:26 +00:00
render(
() => (
<Router>
2022-11-25 15:45:26 +00:00
<App />
</Router>
),
document.getElementById('root') as HTMLElement
);