✨ (wake lock) ask for permission to lock the screen
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user