wake lock: better permissions handling

This commit is contained in:
wea_ondara
2023-10-06 19:49:31 +02:00
parent 91179a2794
commit b9eb376d1a
3 changed files with 23 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ import {Progress} from '@/data/service/MangaUpdatesDataService';
import {Options, Vue} from 'vue-class-component';
import {ServiceStore} from '@/stores/ServiceStore';
import {BSpinner} from 'bootstrap-vue-next';
import {toast} from 'vue3-toastify';
@Options({
name: 'MangaUpdatesUpdater',
@@ -35,10 +36,7 @@ export default class MangaUpdatesUpdater extends Vue {
//event handler
async onUpdateMangaUpdatesDb(): Promise<void> {
this.progressType = 'starting';
try {
this.wakeLock = await navigator.wakeLock.request();
} catch (_) {
}
await this.tryAcquireWakeLock();
this.serviceStore.mangaUpdatesDataService.updateDb(this.progress);
};
@@ -67,6 +65,19 @@ export default class MangaUpdatesUpdater extends Vue {
this.progressValue = null;
this.progressMax = null;
}
//functions
private async tryAcquireWakeLock(): Promise<void> {
try {
if (navigator.wakeLock) {
this.wakeLock = await navigator.wakeLock.request('screen');
} else {
toast.warning(this.$t('wakeLock.permissionDenied'));
}
} catch (err: any) {
toast.warning(this.$t('wakelock.notSupported'));
}
}
}
</script>

View File

@@ -39,6 +39,10 @@ export const messagesDe = {
title: 'Titel',
},
search: 'Suche',
wakeLock: {
notSupported: 'Wake lock wird nicht unterstützt! Das Gerät könnte Sync-Funktion unterbrechen.',
permissionDenied: 'Wake lock ist nicht erlaubt! Das Gerät könnte Sync-Funktion unterbrechen.',
},
};
export const datetimeFormatsDe = {

View File

@@ -40,6 +40,10 @@ export const messagesEn = {
title: 'Title',
},
search: 'Search',
wakeLock: {
notSupported: 'Wake lock is not supported! The device could pause the sync function.',
permissionDenied: 'Wake lock is not allowed! The device could pause the sync function.',
},
};
export const datetimeFormatsEn = {