-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can't work on the background.
- Loading branch information
Showing
5 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { logger } from 'src/logger'; | ||
|
||
export function wakeLock() { | ||
let wakeLockPromise: Promise<WakeLockSentinel> | null = null; | ||
|
||
const listener = () => { | ||
if (document.visibilityState === 'visible') { | ||
wakeLockPromise = navigator.wakeLock?.request('screen'); | ||
|
||
// log | ||
wakeLockPromise?.then((wakeLock) => { | ||
logger.info('wake lock created!'); | ||
wakeLock.addEventListener('release', () => { | ||
logger.info('wake lock released!'); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
listener(); | ||
|
||
// 当页面处于非活动状态时该锁自动失效 | ||
document.addEventListener('visibilitychange', listener); | ||
return async () => { | ||
document.removeEventListener('visibilitychange', listener); | ||
|
||
(await wakeLockPromise)?.release(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters