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
32 changes: 29 additions & 3 deletions src/routes/trackpad.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createFileRoute } from '@tanstack/react-router'
import { useState, useRef } from 'react'
import { useState, useRef, useEffect } from 'react'
import { useRemoteConnection } from '../hooks/useRemoteConnection';
import { useTrackpadGesture } from '../hooks/useTrackpadGesture';
import { ControlBar } from '../components/Trackpad/ControlBar';
Expand All @@ -19,7 +19,9 @@ function TrackpadPage() {
const bufferText = buffer.join(" + ");
const hiddenInputRef = useRef<HTMLInputElement>(null);
const isComposingRef = useRef(false);

const sentinelRef = useRef<any>(null);
const mountedRef = useRef(false);

// Load Client Settings
const [sensitivity] = useState(() => {
if (typeof window === 'undefined') return 1.0;
Expand All @@ -32,7 +34,31 @@ function TrackpadPage() {
const s = localStorage.getItem('rein_invert');
return s ? JSON.parse(s) : false;
});

useEffect(() => {
mountedRef.current = true;
const requestWakeLock = async () => {
try {
if ('wakeLock' in navigator) {
const result = await (navigator as any).wakeLock.request('screen');
if (mountedRef.current) {
sentinelRef.current = result;
} else {
await result.release();
}
}
} catch (err) {
console.warn('Wake lock request failed:', err);
}
};
requestWakeLock();
const handleVisibilityChange = () => document.visibilityState === 'visible' && requestWakeLock();
document.addEventListener('visibilitychange', handleVisibilityChange);
return () => {
mountedRef.current = false;
document.removeEventListener('visibilitychange', handleVisibilityChange);
sentinelRef.current?.release();
};
}, []);
const { status, send, sendCombo } = useRemoteConnection();
// Pass sensitivity and invertScroll to the gesture hook
const { isTracking, handlers } = useTrackpadGesture(send, scrollMode, sensitivity, invertScroll);
Expand Down