Skip to content

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

fix: address code review feedback on GPU device selector

Alcahesteb78be686453
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 9fc5b2bb5..8ac7c4679 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -71,7 +71,7 @@ import { Skeleton } from "./ui/skeleton";
import { Progress } from "./ui/progress";
import { useToast } from "./ui/Toast";
import { useTheme } from "../hooks/useTheme";
-import type { LocalTranscriptionProvider } from "../types/electron";
+import type { GpuDevice, LocalTranscriptionProvider } from "../types/electron";
import logger from "../utils/logger";
import { SettingsRow } from "./ui/SettingsSection";
import { useUsage } from "../hooks/useUsage";
@@ -629,7 +629,7 @@ function AiModelsSection({
function GpuDeviceSelector({ purpose }: { purpose: "transcription" | "intelligence" }) {
const { t } = useTranslation();
- const [gpus, setGpus] = useState<Array<{ index: number; name: string; vramMb: number }>>([]);
+ const [gpus, setGpus] = useState<GpuDevice[]>([]);
const [selectedIndex, setSelectedIndex] = useState("0");
const [loaded, setLoaded] = useState(false);
@@ -641,7 +641,7 @@ function GpuDeviceSelector({ purpose }: { purpose: "transcription" | "intelligen
setGpus(gpuList);
setSelectedIndex(idx);
setLoaded(true);
- });
+ }).catch(() => setLoaded(true));
}, [purpose]);
if (!loaded || gpus.length < 2) return null;
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 9c4a3bbe2..af78a080f 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -998,29 +998,33 @@ class IPCHandlers {
ipcMain.handle("list-gpus", async () => {
const { listNvidiaGpus } = require("../utils/gpuDetection");
- const gpus = await listNvidiaGpus();
- debugLogger.info("GPU devices detected", { count: gpus.length, gpus }, "gpu");
- return gpus;
+ return listNvidiaGpus();
});
ipcMain.handle("set-gpu-device-index", async (_event, purpose, index) => {
- const idx = String(parseInt(index, 10));
- if (isNaN(parseInt(index, 10)) || parseInt(index, 10) < 0) {
+ if (purpose !== "transcription" && purpose !== "intelligence") {
return { success: false };
}
+ const parsed = parseInt(index, 10);
+ if (isNaN(parsed) || parsed < 0) {
+ return { success: false };
+ }
+ const idx = String(parsed);
const key = purpose === "intelligence" ? "INTELLIGENCE_GPU_INDEX" : "TRANSCRIPTION_GPU_INDEX";
const oldIdx = process.env[key] || "0";
process.env[key] = idx;
- this.environmentManager.saveAllKeysToEnvFile().catch(() => {});
+ this.environmentManager.saveAllKeysToEnvFile().catch((err) => {
+ debugLogger.error("Failed to persist GPU index", { error: err.message }, "gpu");
+ });
if (oldIdx !== idx) {
try {
- if (purpose === "transcription" && this.whisperManager?.process) {
+ if (purpose === "transcription" && this.whisperManager?.serverManager?.process) {
debugLogger.info("Restarting whisper-server for GPU change", { from: oldIdx, to: idx }, "gpu");
- const modelPath = this.whisperManager.modelPath;
- await this.whisperManager.stop();
- if (modelPath) {
- await this.whisperManager.start(modelPath, { useCuda: !!process.env.WHISPER_CUDA_ENABLED });
+ const modelName = this.whisperManager.currentServerModel;
+ await this.whisperManager.stopServer();
+ if (modelName) {
+ await this.whisperManager.startServer(modelName, { useCuda: !!process.env.WHISPER_CUDA_ENABLED });
}
}
if (purpose === "intelligence") {
@@ -1043,6 +1047,9 @@ class IPCHandlers {
});
ipcMain.handle("get-gpu-device-index", async (_event, purpose) => {
+ if (purpose !== "transcription" && purpose !== "intelligence") {
+ return "0";
+ }
const key = purpose === "intelligence" ? "INTELLIGENCE_GPU_INDEX" : "TRANSCRIPTION_GPU_INDEX";
return process.env[key] || "0";
});
diff --git a/src/utils/gpuDetection.js b/src/utils/gpuDetection.js
index f0437825f..83d81802a 100644
--- a/src/utils/gpuDetection.js
+++ b/src/utils/gpuDetection.js
@@ -66,7 +66,7 @@ function listNvidiaGpus() {
return;
}
- cachedGpuList = stdout
+ const gpus = stdout
.trim()
.split("\n")
.map((line) => {
@@ -79,7 +79,8 @@ function listNvidiaGpus() {
})
.filter((g) => !isNaN(g.index));
- resolve(cachedGpuList);
+ if (gpus.length > 0) cachedGpuList = gpus;
+ resolve(gpus);
}
);
});