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 {Options, Vue} from 'vue-class-component';
import {ServiceStore} from '@/stores/ServiceStore'; import {ServiceStore} from '@/stores/ServiceStore';
import {BSpinner} from 'bootstrap-vue-next'; import {BSpinner} from 'bootstrap-vue-next';
import {toast} from 'vue3-toastify';
@Options({ @Options({
name: 'MangaUpdatesUpdater', name: 'MangaUpdatesUpdater',
@@ -35,10 +36,7 @@ export default class MangaUpdatesUpdater extends Vue {
//event handler //event handler
async onUpdateMangaUpdatesDb(): Promise<void> { async onUpdateMangaUpdatesDb(): Promise<void> {
this.progressType = 'starting'; this.progressType = 'starting';
try { await this.tryAcquireWakeLock();
this.wakeLock = await navigator.wakeLock.request();
} catch (_) {
}
this.serviceStore.mangaUpdatesDataService.updateDb(this.progress); this.serviceStore.mangaUpdatesDataService.updateDb(this.progress);
}; };
@@ -67,6 +65,19 @@ export default class MangaUpdatesUpdater extends Vue {
this.progressValue = null; this.progressValue = null;
this.progressMax = 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> </script>

View File

@@ -39,6 +39,10 @@ export const messagesDe = {
title: 'Titel', title: 'Titel',
}, },
search: 'Suche', 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 = { export const datetimeFormatsDe = {

View File

@@ -40,6 +40,10 @@ export const messagesEn = {
title: 'Title', title: 'Title',
}, },
search: 'Search', 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 = { export const datetimeFormatsEn = {