Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/routes/trackpad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,56 @@ function TrackpadPage() {
}
}, [keyboardOpen])

// Keep the mobile screen awake while using the trackpad
useEffect(() => {
let wakeLock: WakeLockSentinel | null = null
let isMounted = true

const requestWakeLock = async () => {
if (typeof window === "undefined" || !("wakeLock" in navigator)) {
return
}
if (wakeLock && !wakeLock.released) {
return
}

try {
const sentinel = await navigator.wakeLock.request("screen")

if (!isMounted) {
sentinel.release().catch(() => {})
return
}

if (wakeLock && !wakeLock.released) {
wakeLock.release().catch(() => {})
}

wakeLock = sentinel
} catch (err) {
console.warn("[WakeLock] Failed to acquire screen wake lock:", err)
}
}

requestWakeLock()

const handleVisibilityChange = () => {
if (document.visibilityState === "visible") {
requestWakeLock()
}
}

document.addEventListener("visibilitychange", handleVisibilityChange)

return () => {
isMounted = false
document.removeEventListener("visibilitychange", handleVisibilityChange)
if (wakeLock && !wakeLock.released) {
wakeLock.release().catch(() => {})
}
}
}, [])
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const toggleKeyboard = () => setKeyboardOpen((prev) => !prev)
const focusInput = () => hiddenInputRef.current?.focus()

Expand Down
Loading