(wake lock) ask for permission to lock the screen

This commit is contained in:
2020-07-14 10:57:41 +02:00
parent d35479f271
commit c5a047dce6
2 changed files with 45 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import { ref, computed, watch } from '@vue/composition-api'
import { StopwatchState } from '@/types/StopwatchState'
import { notify } from '@/utils/notification'
import { useInterval } from './useInterval'
import { useWakeLock } from './useWakeLock'
const format = (num: number) => {
return num.toString().padStart(2, '0')
@@ -15,6 +16,8 @@ const formatSeconds = (seconds: number) => {
}
export const useTimer = () => {
const { askWakeLockPermission, releaseWakeLock } = useWakeLock()
const timeState = ref<StopwatchState>('stopped')
const seconds = ref(0)
const { interval } = useInterval()
@@ -33,6 +36,7 @@ export const useTimer = () => {
})
const start = () => {
askWakeLockPermission()
timeState.value = 'started'
stopwatchId = setInterval(() => {
@@ -56,6 +60,7 @@ export const useTimer = () => {
}
const pause = () => {
releaseWakeLock()
timeState.value = 'stopped'
if (stopwatchId) {
clearInterval(stopwatchId)