From 3946b5ef2f6b608e701df85c8b4f70c0dca83d9d Mon Sep 17 00:00:00 2001 From: Nexmoe <16796652+nexmoe@users.noreply.github.com> Date: Sat, 29 Nov 2025 11:10:16 +0800 Subject: [PATCH] feat: resolve ~ in config paths before passing to engine (#34) --- src/main/download-engine/args-builder.ts | 6 ++++-- src/main/lib/download-engine.ts | 11 +++++++---- src/main/utils/path-helpers.ts | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/main/utils/path-helpers.ts diff --git a/src/main/download-engine/args-builder.ts b/src/main/download-engine/args-builder.ts index 788cee1..5c498e6 100644 --- a/src/main/download-engine/args-builder.ts +++ b/src/main/download-engine/args-builder.ts @@ -1,5 +1,6 @@ import path from 'node:path' import type { AppSettings, DownloadOptions } from '../../shared/types' +import { resolvePathWithHome } from '../utils/path-helpers' export const sanitizeFilenameTemplate = (template: string): string => { const trimmed = template.trim() @@ -115,8 +116,9 @@ export const buildDownloadArgs = ( args.push('--proxy', settings.proxy) } - if (settings.configPath) { - args.push('--config-location', settings.configPath) + const configPath = resolvePathWithHome(settings.configPath) + if (configPath) { + args.push('--config-location', configPath) } args.push(options.url) diff --git a/src/main/lib/download-engine.ts b/src/main/lib/download-engine.ts index c3f3c4f..5a75798 100644 --- a/src/main/lib/download-engine.ts +++ b/src/main/lib/download-engine.ts @@ -20,6 +20,7 @@ import { } from '../download-engine/format-utils' import { settingsManager } from '../settings' import { scopedLoggers } from '../utils/logger' +import { resolvePathWithHome } from '../utils/path-helpers' import { DownloadQueue } from './download-queue' import { ffmpegManager } from './ffmpeg-manager' import { historyManager } from './history-manager' @@ -74,8 +75,9 @@ class DownloadEngine extends EventEmitter { } // Add config file if configured - if (settings.configPath) { - args.push('--config-location', `"${settings.configPath}"`) + const configPath = resolvePathWithHome(settings.configPath) + if (configPath) { + args.push('--config-location', configPath) } args.push(url) @@ -169,8 +171,9 @@ class DownloadEngine extends EventEmitter { } // Add config file if configured - if (settings.configPath) { - args.push('--config-location', `"${settings.configPath}"`) + const configPath = resolvePathWithHome(settings.configPath) + if (configPath) { + args.push('--config-location', configPath) } args.push(url) diff --git a/src/main/utils/path-helpers.ts b/src/main/utils/path-helpers.ts new file mode 100644 index 0000000..cfc0e92 --- /dev/null +++ b/src/main/utils/path-helpers.ts @@ -0,0 +1,19 @@ +import os from 'node:os' +import path from 'node:path' + +export const resolvePathWithHome = (rawPath?: string | null): string | undefined => { + const trimmed = rawPath?.trim() + if (!trimmed) { + return undefined + } + + if (trimmed === '~') { + return os.homedir() + } + + if (trimmed.startsWith('~/') || trimmed.startsWith('~\\')) { + return path.join(os.homedir(), trimmed.slice(2)) + } + + return trimmed +}