mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-29 01:04:18 -04:00 
			
		
		
		
	Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <template>
 | |
|   <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>
 | |
| </template>
 | |
| 
 | |
| <script lang="ts">
 | |
| import { useWakeLock } from "@vueuse/core";
 | |
| 
 | |
| export default defineNuxtComponent({
 | |
|   setup() {
 | |
|     const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock();
 | |
|     const wakeLock = computed({
 | |
|       get: () => isActive.value,
 | |
|       set: () => {
 | |
|         if (isActive.value) {
 | |
|           unlockScreen();
 | |
|         }
 | |
|         else {
 | |
|           lockScreen();
 | |
|         }
 | |
|       },
 | |
|     });
 | |
|     async function lockScreen() {
 | |
|       if (wakeIsSupported) {
 | |
|         console.debug("Wake Lock Requested");
 | |
|         await request("screen");
 | |
|       }
 | |
|     }
 | |
|     async function unlockScreen() {
 | |
|       if (wakeIsSupported || isActive) {
 | |
|         console.debug("Wake Lock Released");
 | |
|         await release();
 | |
|       }
 | |
|     }
 | |
|     onMounted(() => lockScreen());
 | |
|     onUnmounted(() => unlockScreen());
 | |
| 
 | |
|     return {
 | |
|       wakeLock,
 | |
|       wakeIsSupported,
 | |
|     };
 | |
|   },
 | |
| });
 | |
| </script>
 |