VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.
Python aiaudiobookcudadubbingelevenlabs-alternativehuggingfacelocal-firstmlxomnivoice-studiospeech-to-texttext-to-speechtranscriptiontranslatettsvoice-aivoice-cloningvoice-generationvoicestudioworkflow
fix(report-bug): make tool directory discovery non-blocking
debpalash21312b951cb8
diff --git a/electron/src/main/backend.ts b/electron/src/main/backend.tsindex 272c84d8a..5f80f09d7 100644--- a/electron/src/main/backend.ts+++ b/electron/src/main/backend.ts@@ -51,7 +51,7 @@ import {saveRemoteBackend,type RemoteSession,} from './remote-backend';-import { toolSearchDirs } from './tool-path';+import { toolSearchDirs, toolSearchDirsAsync } from './tool-path';import { SetupProgressTracker, cleanProcessLine } from './setup-progress';import { scrubText } from '../shared/utils/scrub';import { DEFAULT_BACKEND_PORT } from '../../../config/app-config.mjs';@@ -313,7 +313,7 @@ async function findUvAsync(): Promise<string | null> {if (await usable(bundled)) return bundled;}const names = process.platform === 'win32' ? ['uv.exe', 'uv'] : ['uv'];- for (const dir of toolSearchDirs()) {+ for (const dir of await toolSearchDirsAsync()) {for (const name of names) {const candidate = join(dir, name);if (await usable(candidate)) return candidate;diff --git a/electron/src/main/tool-path.test.ts b/electron/src/main/tool-path.test.tsindex 60aa07561..b9c9d26bf 100644--- a/electron/src/main/tool-path.test.ts+++ b/electron/src/main/tool-path.test.ts@@ -1,8 +1,8 @@import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { delimiter, join } from 'node:path';-import { describe, expect, it } from 'vitest';-import { envWithToolPath, toolSearchDirs } from './tool-path';+import { describe, expect, it, vi } from 'vitest';+import { envWithToolPath, toolSearchDirs, toolSearchDirsAsync } from './tool-path';describe('toolSearchDirs', () => {it('adds user-level install locations after the inherited PATH on macOS and Linux', () => {@@ -68,3 +68,34 @@ describe('NVM discovery order', () => {}});});++describe('toolSearchDirsAsync', () => {+ it('matches the sync result', async () => {+ const home = mkdtempSync(join(tmpdir(), 'vs-nvm-'));+ try {+ mkdirSync(join(home, '.nvm', 'versions', 'node', 'v22.1.0'), { recursive: true });+ const opts = { env: { PATH: '/usr/bin' }, platform: 'linux' as const, home };+ expect(await toolSearchDirsAsync(opts)).toEqual(toolSearchDirs(opts));+ } finally {+ rmSync(home, { recursive: true, force: true });+ }+ });++ it('never blocks the event loop on a stalled home directory', async () => {+ vi.useFakeTimers();+ try {+ const hang = () => new Promise<string[]>(() => {});+ let settled = false;+ void toolSearchDirsAsync({ platform: 'linux', home: '/stalled', readdirAsync: hang }).then(+ () => (settled = true),+ );+ let deadline = false;+ setTimeout(() => (deadline = true), 1500);+ await vi.advanceTimersByTimeAsync(1500);+ expect(deadline).toBe(true);+ expect(settled).toBe(false);+ } finally {+ vi.useRealTimers();+ }+ });+});diff --git a/electron/src/main/tool-path.ts b/electron/src/main/tool-path.tsindex d702107df..17f3121cf 100644--- a/electron/src/main/tool-path.ts+++ b/electron/src/main/tool-path.ts@@ -1,4 +1,5 @@import { readdirSync } from 'node:fs';+import { readdir } from 'node:fs/promises';import { homedir } from 'node:os';import { delimiter, join } from 'node:path';@@ -6,36 +7,50 @@ interface ToolPathOptions {env?: NodeJS.ProcessEnv;platform?: NodeJS.Platform;home?: string;+ /** Async directory-listing seam (tests); defaults to fs/promises readdir. */+ readdirAsync?: (path: string) => Promise<string[]>;+}++function nvmRoot(home: string): string {+ return join(home, '.nvm', 'versions', 'node');+}++function nvmBinsFrom(root: string, names: string[]): string[] {+ // Newest numeric release first: a lexical sort would put v9 ahead of v24.+ return names+ .flatMap((name) => {+ const match = /^v(\d+)\.(\d+)\.(\d+)$/.exec(name);+ return match ? [{ name, parts: match.slice(1).map(Number) }] : [];+ })+ .sort((a, b) => b.parts[0] - a.parts[0] || b.parts[1] - a.parts[1] || b.parts[2] - a.parts[2])+ .map(({ name }) => join(root, name, 'bin'));}function nvmBinDirs(home: string): string[] {- const root = join(home, '.nvm', 'versions', 'node');+ const root = nvmRoot(home);try {- // Newest numeric release first: a lexical sort would put v9 ahead of v24.- return readdirSync(root)- .flatMap((name) => {- const match = /^v(\d+)\.(\d+)\.(\d+)$/.exec(name);- return match ? [{ name, parts: match.slice(1).map(Number) }] : [];- })- .sort((a, b) => b.parts[0] - a.parts[0] || b.parts[1] - a.parts[1] || b.parts[2] - a.parts[2])- .map(({ name }) => join(root, name, 'bin'));+ return nvmBinsFrom(root, readdirSync(root));} catch {return [];}}-/**- * Directories to search for user-installed CLIs (uv, claude, codex, ...).- *- * A GUI launch (Finder, Explorer, a .desktop file) does not see the shell's- * PATH additions, so the inherited PATH alone misses the standard user-level- * install locations. Inherited entries stay first so an explicit PATH wins.- */-export function toolSearchDirs({- env = process.env,- platform = process.platform,- home = homedir(),-}: ToolPathOptions = {}): string[] {+async function nvmBinDirsAsync(+ home: string,+ list: (path: string) => Promise<string[]>,+): Promise<string[]> {+ const root = nvmRoot(home);+ try {+ return nvmBinsFrom(root, await list(root));+ } catch {+ return [];+ }+}++function assembleDirs(+ { env = process.env, platform = process.platform, home = homedir() }: ToolPathOptions,+ nvm: string[],+): string[] {const inherited = (env.PATH ?? env.Path ?? '').split(delimiter).filter(Boolean);const common = [join(home, '.local', 'bin'),@@ -50,15 +65,31 @@ export function toolSearchDirs({join(env.APPDATA || join(home, 'AppData', 'Roaming'), 'npm'),join(env.LOCALAPPDATA || join(home, 'AppData', 'Local'), 'Programs', 'claude'),]- : [- '/opt/homebrew/bin',- '/usr/local/bin',- join(home, '.npm-global', 'bin'),- ...nvmBinDirs(home),- ];+ : ['/opt/homebrew/bin', '/usr/local/bin', join(home, '.npm-global', 'bin'), ...nvm];return [...new Set([...inherited, ...common, ...extra])];}+/**+ * Directories to search for user-installed CLIs (uv, claude, codex, ...).+ *+ * A GUI launch (Finder, Explorer, a .desktop file) does not see the shell's+ * PATH additions, so the inherited PATH alone misses the standard user-level+ * install locations. Inherited entries stay first so an explicit PATH wins.+ */+export function toolSearchDirs(options: ToolPathOptions = {}): string[] {+ const { platform = process.platform, home = homedir() } = options;+ return assembleDirs(options, platform === 'win32' ? [] : nvmBinDirs(home));+}++/** Non-blocking twin of toolSearchDirs(): the nvm listing never touches the main thread. */+export async function toolSearchDirsAsync(options: ToolPathOptions = {}): Promise<string[]> {+ const { platform = process.platform, home = homedir(), readdirAsync = readdir } = options;+ return assembleDirs(+ options,+ platform === 'win32' ? [] : await nvmBinDirsAsync(home, readdirAsync),+ );+}+/** Copy of `env` whose PATH includes the user-level tool directories. */export function envWithToolPath(options: ToolPathOptions = {}): NodeJS.ProcessEnv {const env = options.env ?? process.env;