Skip to content

Commit

Permalink
Fix screen locking with visibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Jan 5, 2025
1 parent 7799fe7 commit 5a19c05
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/services/KitchenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Falsy } from '@noeldemartin/utils';
import type { RouteLocationRaw } from 'vue-router';

import App from '@/framework/core/facades/App';
import Browser from '@/framework/core/facades/Browser';
import Errors from '@/framework/core/facades/Errors';
import Events from '@/framework/core/facades/Events';
import Router from '@/framework/core/facades/Router';
Expand Down Expand Up @@ -151,6 +152,23 @@ export default class CookbookService extends Service<State, ComputedState, Persi
this.setState({ dishes: [], timers: [], lastPage: null });
});

document.addEventListener('visibilitychange', () => {
if (this.dishes.length === 0) {
return;
}

switch (document.visibilityState) {
case 'hidden':
this.releaseScreen();

break;
case 'visible':
this.lockScreen();

break;
}
});

if (this.dishes.length > 0) {
this.lockScreen();

Expand Down Expand Up @@ -268,7 +286,7 @@ export default class CookbookService extends Service<State, ComputedState, Persi
wakeLock?: { request(type?: 'screen'): Promise<{ release(): Promise<void> }> };
};

if (!typedNavigator.wakeLock) {
if (!Browser.supportsWakeLocking || !typedNavigator.wakeLock) {
return;
}

Expand Down

0 comments on commit 5a19c05

Please sign in to comment.