Skip to content

Commit

Permalink
don't sleep mobile devices when fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye217 committed May 30, 2024
1 parent 3e6b8c2 commit 4023de3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"lucide-react": "^0.379.0",
"monaco-yaml": "^5.1.1",
"next-themes": "^0.3.0",
"nosleep.js": "^0.12.0",
"react": "^18.3.1",
"react-apexcharts": "^1.4.1",
"react-day-picker": "^8.10.1",
Expand Down
5 changes: 5 additions & 0 deletions web/src/hooks/use-fullscreen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { RefObject, useCallback, useEffect, useState } from "react";
import nosleep from "nosleep.js";

const NoSleep = new nosleep();

function getFullscreenElement(): HTMLElement | null {
return (
Expand Down Expand Up @@ -96,9 +99,11 @@ export function useFullscreen<T extends HTMLElement = HTMLElement>(
const toggleFullscreen = useCallback(async () => {
try {
if (!getFullscreenElement()) {
NoSleep.enable();
await enterFullScreen(elementRef.current!);
} else {
await exitFullscreen();
NoSleep.disable();
}
setError(null);
} catch (err) {
Expand Down

0 comments on commit 4023de3

Please sign in to comment.