Skip to content

Commit

Permalink
Silence wake lock errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Jan 2, 2025
1 parent 75f97a9 commit 4cf0e2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/framework/core/services/ErrorsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ export default class ErrorsService extends Service<State, ComputedState> {
UI.openModal(UI.resolveComponent(ApplicationComponent.ErrorReportModal), { reports });
}

public reportDevelopmentError(error: ErrorSource, message?: string): void {
if (!App.isDevelopment) {
return;
}

if (message) {
// eslint-disable-next-line no-console
console.warn(message);
}

this.logError(error);
}

public async report(error: ErrorSource, message?: string): Promise<void> {
if (await this.handleError(error)) {
return;
Expand Down
13 changes: 10 additions & 3 deletions src/services/KitchenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toRaw } from 'vue';
import type { RouteLocationRaw } from 'vue-router';

import App from '@/framework/core/facades/App';
import Errors from '@/framework/core/facades/Errors';
import Events from '@/framework/core/facades/Events';
import Router from '@/framework/core/facades/Router';
import Service from '@/framework/core/Service';
Expand Down Expand Up @@ -40,7 +41,7 @@ export default class CookbookService extends Service<State, ComputedState, Persi

public static persist: Array<keyof PersistedState> = ['dish', 'timers', 'wakeLock', 'lastRoute'];

private screenLock: Promise<{ release(): Promise<void> }> | null = null;
private screenLock: Promise<void | { release(): Promise<void> }> | null = null;
private timeouts: WeakMap<Timer, ReturnType<typeof setTimeout>> = new WeakMap();

public async open(): Promise<void> {
Expand Down Expand Up @@ -191,15 +192,21 @@ export default class CookbookService extends Service<State, ComputedState, Persi
return;
}

this.screenLock = typedNavigator.wakeLock.request('screen');
try {
this.screenLock = typedNavigator.wakeLock.request('screen').catch((error) => {
Errors.reportDevelopmentError(error, 'Could not request screen wake lock');
});
} catch (error) {
Errors.reportDevelopmentError(error, 'Could not request screen wake lock');
}
}

protected releaseScreen(): void {
if (!this.screenLock) {
return;
}

this.screenLock.then(lock => lock.release());
this.screenLock.then(lock => lock?.release());
this.screenLock = null;
}

Expand Down

0 comments on commit 4cf0e2f

Please sign in to comment.