stop via tray

This commit is contained in:
Siddharth
2025-10-17 20:05:17 -07:00
parent ec37cd7f11
commit c3eb97116a
9 changed files with 164 additions and 19 deletions
+24 -12
View File
@@ -13,8 +13,30 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
const chunks = useRef<Blob[]>([]);
const startTime = useRef<number>(0);
const stopRecording = useRef(() => {
if (mediaRecorder.current?.state === "recording") {
if (stream.current) {
stream.current.getTracks().forEach(track => track.stop());
}
mediaRecorder.current.stop();
setRecording(false);
window.electronAPI.stopMouseTracking();
window.electronAPI?.setRecordingState(false);
}
});
useEffect(() => {
let cleanup: (() => void) | undefined;
if (window.electronAPI?.onStopRecordingFromTray) {
cleanup = window.electronAPI.onStopRecordingFromTray(() => {
stopRecording.current();
});
}
return () => {
if (cleanup) cleanup();
if (mediaRecorder.current?.state === "recording") {
mediaRecorder.current.stop();
}
@@ -91,6 +113,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
recorder.start(1000);
startTime.current = Date.now();
setRecording(true);
window.electronAPI?.setRecordingState(true);
} catch (error) {
console.error('Failed to start recording:', error);
setRecording(false);
@@ -101,19 +124,8 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
}
};
const stopRecording = () => {
if (mediaRecorder.current?.state === "recording") {
if (stream.current) {
stream.current.getTracks().forEach(track => track.stop());
}
mediaRecorder.current.stop();
setRecording(false);
window.electronAPI.stopMouseTracking();
}
};
const toggleRecording = () => {
recording ? stopRecording() : startRecording();
recording ? stopRecording.current() : startRecording();
};
return { recording, toggleRecording };
+2
View File
@@ -36,5 +36,7 @@ interface Window {
message?: string
error?: string
}>
setRecordingState: (recording: boolean) => Promise<void>
onStopRecordingFromTray: (callback: () => void) => () => void
}
}