File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,11 +70,11 @@ export const useInit = (props: MangaProps) => {
7070 state . prop . onExit = ( isEnd ?: boolean | Event ) => {
7171 playAnimation ( refs . exit ) ;
7272 props . onExit ?.( Boolean ( isEnd ) ) ;
73- document . exitFullscreen ( ) ;
7473 setState ( ( draftState ) => {
7574 if ( isEnd ) draftState . activePageIndex = 0 ;
7675 draftState . show . endPage = undefined ;
7776 } ) ;
77+ if ( document . fullscreenElement ) document . exitFullscreen ( ) ;
7878 } ;
7979 } ,
8080 onPrev ( state ) {
Original file line number Diff line number Diff line change @@ -615,3 +615,31 @@ export abstract class AnimationFrame {
615615 this . animationId = 0 ;
616616 } ;
617617}
618+
619+ /** 锁定屏幕禁止自动熄屏 */
620+ export class WakeLock {
621+ isSupported = false ;
622+
623+ lock : WakeLockSentinel | null = null ;
624+
625+ constructor ( ) {
626+ if ( ! ( 'wakeLock' in navigator ) ) return ;
627+ this . isSupported = true ;
628+ }
629+
630+ on = async ( ) => {
631+ if ( ! this . isSupported ) return null ;
632+ try {
633+ this . lock = await navigator . wakeLock . request ( 'screen' ) ;
634+ return this . lock . released ;
635+ } catch {
636+ return false ;
637+ }
638+ } ;
639+
640+ off = async ( ) => {
641+ if ( ! this . lock ) return ;
642+ await this . lock . release ( ) ;
643+ this . lock = null ;
644+ } ;
645+ }
Original file line number Diff line number Diff line change 88 createRootMemo ,
99 mountComponents ,
1010 querySelector ,
11+ WakeLock ,
1112} from 'helper' ;
1213
1314import { DownloadButton } from '../../components/DownloadButton' ;
@@ -68,6 +69,8 @@ export const useManga = async (initProps?: Partial<MangaProps>) => {
6869 const htmlStyle = document . documentElement . style ;
6970 let lastOverflow = htmlStyle . overflow ;
7071
72+ const wakeLock = new WakeLock ( ) ;
73+
7174 createEffectOn (
7275 createRootMemo ( ( ) => props . show && props . imgList . length > 0 ) ,
7376 ( show ) => {
@@ -77,10 +80,12 @@ export const useManga = async (initProps?: Partial<MangaProps>) => {
7780 htmlStyle . setProperty ( 'overflow' , 'hidden' , 'important' ) ;
7881 htmlStyle . setProperty ( 'scrollbar-width' , 'none' , 'important' ) ;
7982 if ( store . option . autoFullscreen ) refs . root . requestFullscreen ( ) ;
83+ wakeLock . on ( ) ;
8084 } else {
8185 dom . removeAttribute ( 'show' ) ;
8286 htmlStyle . overflow = lastOverflow ;
8387 htmlStyle . removeProperty ( 'scrollbar-width' ) ;
88+ wakeLock . off ( ) ;
8489 }
8590 } ,
8691 { defer : true } ,
You can’t perform that action at this time.
0 commit comments