mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 15:49:42 +02:00
feat: Shopping list UI overhaul - add wakelock (#4236)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
8fe1b0c123
commit
28b0190648
3 changed files with 52 additions and 47 deletions
49
frontend/components/global/WakelockSwitch.vue
Normal file
49
frontend/components/global/WakelockSwitch.vue
Normal file
|
@ -0,0 +1,49 @@
|
|||
<template>
|
||||
<div
|
||||
v-if="wakeIsSupported"
|
||||
class="d-print-none d-flex px-2"
|
||||
:class="$vuetify.breakpoint.smAndDown ? 'justify-center' : 'justify-end'"
|
||||
>
|
||||
<v-switch v-model="wakeLock" small :label="$t('recipe.screen-awake')" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed, onMounted, onUnmounted } from "@nuxtjs/composition-api";
|
||||
import { useWakeLock } from "@vueuse/core";
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock();
|
||||
const wakeLock = computed({
|
||||
get: () => isActive,
|
||||
set: () => {
|
||||
if (isActive.value) {
|
||||
unlockScreen();
|
||||
} else {
|
||||
lockScreen();
|
||||
}
|
||||
},
|
||||
});
|
||||
async function lockScreen() {
|
||||
if (wakeIsSupported) {
|
||||
console.log("Wake Lock Requested");
|
||||
await request("screen");
|
||||
}
|
||||
}
|
||||
async function unlockScreen() {
|
||||
if (wakeIsSupported || isActive) {
|
||||
console.log("Wake Lock Released");
|
||||
await release();
|
||||
}
|
||||
}
|
||||
onMounted(() => lockScreen());
|
||||
onUnmounted(() => unlockScreen());
|
||||
|
||||
return {
|
||||
wakeLock,
|
||||
wakeIsSupported,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue