Cherry picking 57d17a1fa6 (Requesting a wake lock so that the screen is not dimmed while using the app.)

This commit is contained in:
Eric van der Vlist 2022-11-02 22:33:03 +01:00
parent 8e2a68fb0f
commit 7f03b0bca4
1 changed files with 29 additions and 1 deletions

View File

@ -40,6 +40,34 @@ import CurrentLocation from './components/map/CurrentLocation';
setupIonicReact(); setupIonicReact();
// 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);
requestWakeLock();
const initialScope: MapScope = { const initialScope: MapScope = {
center: { lat: -37.8403508, lon: 77.5539501 }, center: { lat: -37.8403508, lon: 77.5539501 },
zoom: 13, zoom: 13,
@ -71,7 +99,7 @@ const App: React.FC = () => {
scope={scope} scope={scope}
setScope={debounce(setScope, 1000)} setScope={debounce(setScope, 1000)}
numberOfTiledLayers={5} numberOfTiledLayers={5}
markers={[<CurrentLocation key='currentLocation'/>]} markers={[<CurrentLocation key='currentLocation' />]}
/> />
</IonApp> </IonApp>
</IonContent> </IonContent>