Cleanup wake lock
This commit is contained in:
@@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
- (**Migration**) Add "in library" indicator
|
||||
- (**Settings/WebView**) Add setting to enable/disable WebView
|
||||
- (**Settings/Sync**) Add sync settings
|
||||
- (**Reader**) Add Wake lock screen while reading
|
||||
- (**Reader**) Add setting to keep the screen on while reading
|
||||
- (**Extension**) Support installing external JARs
|
||||
- (**Reader**) Add auto background color setting
|
||||
|
||||
|
||||
@@ -8,12 +8,18 @@
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export function useReaderWakeLock(shouldLock: boolean) {
|
||||
export const useWakeLock = (shouldLock: boolean) => {
|
||||
const wakeLockSentinelRef = useRef<WakeLockSentinel | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!('wakeLock' in navigator)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldLock) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestWakeLock = async () => {
|
||||
try {
|
||||
if (wakeLockSentinelRef.current) {
|
||||
@@ -41,16 +47,12 @@ export function useReaderWakeLock(shouldLock: boolean) {
|
||||
}
|
||||
};
|
||||
|
||||
if (shouldLock) {
|
||||
requestWakeLock();
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||
} else {
|
||||
releaseWakeLock();
|
||||
}
|
||||
requestWakeLock();
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||
releaseWakeLock();
|
||||
};
|
||||
}, [shouldLock]);
|
||||
}
|
||||
};
|
||||
@@ -28,7 +28,7 @@ import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
||||
import type { NavbarContextType } from '@/features/navigation-bar/NavigationBar.types.ts';
|
||||
import { withPropsFrom } from '@/base/hoc/withPropsFrom.tsx';
|
||||
import { useReaderResetStates } from '@/features/reader/hooks/useReaderResetStates.ts';
|
||||
import { useReaderWakeLock } from '@/features/reader/wake-lock/useReaderWakeLock.ts';
|
||||
import { useWakeLock } from '@/base/hooks/useWakeLock.ts';
|
||||
import { useReaderSetSettingsState } from '@/features/reader/hooks/useReaderSetSettingsState.ts';
|
||||
import { useReaderShowSettingPreviewOnChange } from '@/features/reader/hooks/useReaderShowSettingPreviewOnChange.ts';
|
||||
import { useReaderSetChaptersState } from '@/features/reader/hooks/useReaderSetChaptersState.ts';
|
||||
@@ -160,7 +160,7 @@ const BaseReader = ({
|
||||
}, [mangaResponse.data?.manga]);
|
||||
|
||||
useReaderResetStates();
|
||||
useReaderWakeLock(shouldWakeLockScreen);
|
||||
useWakeLock(shouldWakeLockScreen);
|
||||
useReaderSetSettingsState(
|
||||
mangaResponse,
|
||||
defaultSettingsResponse,
|
||||
|
||||
Reference in New Issue
Block a user