Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: prevent race condition in Python installation check

Gabriel Stein66d6d331acce
diff --git a/src/hooks/usePython.ts b/src/hooks/usePython.ts
index 3b5e5e0b7..bfe56b10a 100644
--- a/src/hooks/usePython.ts
+++ b/src/hooks/usePython.ts
@@ -1,4 +1,5 @@
-import { useState, useEffect, useCallback } from "react";
+import { useState, useEffect, useCallback, useRef } from "react";
+import logger from "../utils/logger";
interface PythonInstallation {
installed: boolean;
@@ -43,12 +44,15 @@ export function usePython(showAlertDialog: ShowAlertDialog) {
const [isChecking, setIsChecking] = useState<boolean>(false);
const [hasChecked, setHasChecked] = useState<boolean>(false);
+ const isCheckingRef = useRef(false);
+
const checkPythonInstallation = useCallback(async () => {
- if (isChecking) {
- return pythonInfo || { installed: false };
+ if (isCheckingRef.current) {
+ return pythonInfo;
}
try {
+ isCheckingRef.current = true;
setIsChecking(true);
if (!window.electronAPI) {
@@ -64,13 +68,15 @@ export function usePython(showAlertDialog: ShowAlertDialog) {
}
return { installed: false };
} catch (error) {
+ logger.error("Python installation check failed", error, "usePython");
setPythonInstalled(false);
return { installed: false };
} finally {
+ isCheckingRef.current = false;
setIsChecking(false);
setHasChecked(true);
}
- }, [isChecking, pythonInfo]);
+ }, [pythonInfo]);
const installPython = useCallback(async () => {
if (!window.electronAPI) {