2024-09-28 10:16:06 -05:00
|
|
|
<template>
|
2025-06-20 00:09:12 +07:00
|
|
|
<div
|
|
|
|
|
v-if="wakeIsSupported"
|
|
|
|
|
class="d-print-none d-flex px-2"
|
|
|
|
|
:class="$vuetify.display.smAndDown ? 'justify-center' : 'justify-end'"
|
|
|
|
|
>
|
|
|
|
|
<v-switch
|
|
|
|
|
v-model="wakeLock"
|
|
|
|
|
color="primary"
|
|
|
|
|
:label="$t('recipe.screen-awake')"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2024-09-28 10:16:06 -05:00
|
|
|
</template>
|
|
|
|
|
|
2026-03-23 21:18:25 +01:00
|
|
|
<script setup lang="ts">
|
2024-09-28 10:16:06 -05:00
|
|
|
import { useWakeLock } from "@vueuse/core";
|
2026-05-11 14:12:50 -05:00
|
|
|
import { useUserExperiencePreferences } from "~/composables/use-users/preferences";
|
2024-09-28 10:16:06 -05:00
|
|
|
|
2026-03-23 21:18:25 +01:00
|
|
|
const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock();
|
2026-05-11 14:12:50 -05:00
|
|
|
const userExperiencePreferences = useUserExperiencePreferences();
|
|
|
|
|
|
|
|
|
|
function handleLock() {
|
|
|
|
|
if (userExperiencePreferences.value.lockScreen) {
|
|
|
|
|
lockScreen();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
unlockScreen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 21:18:25 +01:00
|
|
|
const wakeLock = computed({
|
2026-05-11 14:12:50 -05:00
|
|
|
get: () => userExperiencePreferences.value.lockScreen,
|
2026-03-23 21:18:25 +01:00
|
|
|
set: () => {
|
2026-05-11 14:12:50 -05:00
|
|
|
userExperiencePreferences.value.lockScreen = !userExperiencePreferences.value.lockScreen;
|
|
|
|
|
handleLock();
|
2025-06-20 00:09:12 +07:00
|
|
|
},
|
2024-09-28 10:16:06 -05:00
|
|
|
});
|
2026-03-23 21:18:25 +01:00
|
|
|
async function lockScreen() {
|
|
|
|
|
if (wakeIsSupported) {
|
|
|
|
|
console.debug("Wake Lock Requested");
|
|
|
|
|
await request("screen");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async function unlockScreen() {
|
2026-05-11 14:12:50 -05:00
|
|
|
if (wakeIsSupported || isActive.value) {
|
2026-03-23 21:18:25 +01:00
|
|
|
console.debug("Wake Lock Released");
|
|
|
|
|
await release();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-11 14:12:50 -05:00
|
|
|
onMounted(() => handleLock());
|
2026-03-23 21:18:25 +01:00
|
|
|
onUnmounted(() => unlockScreen());
|
2024-09-28 10:16:06 -05:00
|
|
|
</script>
|