-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent computer from going to sleep mode every breaks. Mention…
… here #84
- Loading branch information
Showing
6 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
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,48 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
import VideoMp4 from "assets/videos/muted-blank.mp4"; | ||
import VideoOGV from "assets/videos/muted-blank.ogv"; | ||
|
||
const useSleepMode = () => { | ||
const _video = useRef(document.createElement("video")); | ||
|
||
useEffect(() => { | ||
const _videoStyle: React.CSSProperties = { | ||
position: "absolute", | ||
top: "0", | ||
left: "0", | ||
width: "0", | ||
height: "0", | ||
}; | ||
|
||
Object.assign(_video.current.style, _videoStyle); | ||
|
||
const _source_mp4 = document.createElement("source"); | ||
_source_mp4.setAttribute("src", VideoMp4); | ||
_source_mp4.setAttribute("type", "video/mp4"); | ||
|
||
_video.current.appendChild(_source_mp4); | ||
|
||
const _source_ogg = document.createElement("source"); | ||
_source_ogg.setAttribute("src", VideoOGV); | ||
_source_ogg.setAttribute("type", "video/ogg"); | ||
|
||
_video.current.appendChild(_source_ogg); | ||
|
||
document.body.appendChild(_video.current); | ||
}, [_video]); | ||
|
||
const preventSleep = () => { | ||
_video.current.setAttribute("loop", "loop"); | ||
_video.current.play(); | ||
}; | ||
|
||
const allowSleep = () => { | ||
_video.current.removeAttribute("loop"); | ||
_video.current.pause(); | ||
}; | ||
|
||
return { preventSleep, allowSleep }; | ||
}; | ||
|
||
export { useSleepMode }; |