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 {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>
|
||||||
|
|
||||||
|
|||||||
@@ -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 = {
|
||||||
|
|||||||
@@ -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 = {
|
||||||
|
|||||||
Reference in New Issue
Block a user