| 
									
										
										
										
											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> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							|  |  |  | import { useWakeLock } from "@vueuse/core"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							|  |  |  |   setup() { | 
					
						
							|  |  |  |     const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock(); | 
					
						
							|  |  |  |     const wakeLock = computed({ | 
					
						
							|  |  |  |       get: () => isActive.value, | 
					
						
							|  |  |  |       set: () => { | 
					
						
							|  |  |  |         if (isActive.value) { | 
					
						
							|  |  |  |           unlockScreen(); | 
					
						
							| 
									
										
										
										
											2024-09-28 10:16:06 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         else { | 
					
						
							|  |  |  |           lockScreen(); | 
					
						
							| 
									
										
										
										
											2024-09-28 10:16:06 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     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()); | 
					
						
							| 
									
										
										
										
											2024-09-28 10:16:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     return { | 
					
						
							|  |  |  |       wakeLock, | 
					
						
							|  |  |  |       wakeIsSupported, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2024-09-28 10:16:06 -05:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |