wake lock: better permissions handling
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user