From e18e9d949427754359537a4a7c8d9c2bb2355435 Mon Sep 17 00:00:00 2001 From: chyoo Date: Thu, 2 Jul 2026 13:41:59 +0900 Subject: [PATCH] store downloaded apps under user app directory --- src/main/index.ts | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index b1885c1..dbc53b6 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -57,11 +57,28 @@ function getLauncherDir(): string { return dirname(process.execPath) } -function resolveExecPath(execPath?: string): string | undefined { - if (!execPath) return undefined - return execPath.startsWith('./') - ? join(getLauncherDir(), execPath.slice(2)) - : execPath +function getUserAppsDir(): string { + return join(app.getPath('home'), '.local', 'share', 'autonomy-studio', 'apps') +} + +function sanitizeAppFileName(appName: string): string { + return appName.trim().replace(/[^a-z0-9._-]+/gi, '-').replace(/^-+|-+$/g, '') || 'app' +} + +function getDefaultExecPath(appName?: string): string | undefined { + if (!appName) return undefined + return join(getUserAppsDir(), `${sanitizeAppFileName(appName)}.AppImage`) +} + +function resolveExecPath(execPath?: string, appName?: string): string | undefined { + const trimmed = execPath?.trim() + if (!trimmed) return getDefaultExecPath(appName) + if (trimmed.startsWith('~/')) return join(app.getPath('home'), trimmed.slice(2)) + if (trimmed.startsWith('${HOME}/')) return join(app.getPath('home'), trimmed.slice('${HOME}/'.length)) + if (trimmed.startsWith('$HOME/')) return join(app.getPath('home'), trimmed.slice('$HOME/'.length)) + return trimmed.startsWith('./') || trimmed.startsWith('../') + ? resolve(getUserAppsDir(), trimmed) + : trimmed } function getWorkspaceRoot(): string { @@ -658,7 +675,7 @@ function createWindow(): void { } } - const targetPath = resolveExecPath(payload.execPath) + const targetPath = resolveExecPath(payload.execPath, payload.appName) return { installed: targetPath ? existsSync(targetPath) : false, @@ -673,7 +690,7 @@ function createWindow(): void { execPath?: string latestVersion?: string }) => { - const targetPath = resolveExecPath(payload.execPath) + const targetPath = resolveExecPath(payload.execPath, payload.appName) if (!targetPath) throw new Error('설치 경로가 설정되지 않았습니다.') await downloadFile(payload.downloadUrl, targetPath, (progress) => { @@ -781,7 +798,7 @@ function createWindow(): void { mainWindow.minimize() // ── 별도 Electron 프로세스로 실행 ── - const resolvedExecPath = resolveExecPath(execPath) + const resolvedExecPath = resolveExecPath(execPath, appName) const resolvedDevAppPath = resolveDevAppPath(devAppPath) ?? getDefaultDevAppPath(appName) if (is.dev && resolvedDevAppPath && !isRunnableDevAppPath(resolvedDevAppPath)) { dialog.showErrorBox(