store downloaded apps under user app directory

This commit is contained in:
2026-07-02 13:41:59 +09:00
parent a294b724b4
commit e18e9d9494
+25 -8
View File
@@ -57,11 +57,28 @@ function getLauncherDir(): string {
return dirname(process.execPath) return dirname(process.execPath)
} }
function resolveExecPath(execPath?: string): string | undefined { function getUserAppsDir(): string {
if (!execPath) return undefined return join(app.getPath('home'), '.local', 'share', 'autonomy-studio', 'apps')
return execPath.startsWith('./') }
? join(getLauncherDir(), execPath.slice(2))
: execPath 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 { function getWorkspaceRoot(): string {
@@ -658,7 +675,7 @@ function createWindow(): void {
} }
} }
const targetPath = resolveExecPath(payload.execPath) const targetPath = resolveExecPath(payload.execPath, payload.appName)
return { return {
installed: targetPath ? existsSync(targetPath) : false, installed: targetPath ? existsSync(targetPath) : false,
@@ -673,7 +690,7 @@ function createWindow(): void {
execPath?: string execPath?: string
latestVersion?: string latestVersion?: string
}) => { }) => {
const targetPath = resolveExecPath(payload.execPath) const targetPath = resolveExecPath(payload.execPath, payload.appName)
if (!targetPath) throw new Error('설치 경로가 설정되지 않았습니다.') if (!targetPath) throw new Error('설치 경로가 설정되지 않았습니다.')
await downloadFile(payload.downloadUrl, targetPath, (progress) => { await downloadFile(payload.downloadUrl, targetPath, (progress) => {
@@ -781,7 +798,7 @@ function createWindow(): void {
mainWindow.minimize() mainWindow.minimize()
// ── 별도 Electron 프로세스로 실행 ── // ── 별도 Electron 프로세스로 실행 ──
const resolvedExecPath = resolveExecPath(execPath) const resolvedExecPath = resolveExecPath(execPath, appName)
const resolvedDevAppPath = resolveDevAppPath(devAppPath) ?? getDefaultDevAppPath(appName) const resolvedDevAppPath = resolveDevAppPath(devAppPath) ?? getDefaultDevAppPath(appName)
if (is.dev && resolvedDevAppPath && !isRunnableDevAppPath(resolvedDevAppPath)) { if (is.dev && resolvedDevAppPath && !isRunnableDevAppPath(resolvedDevAppPath)) {
dialog.showErrorBox( dialog.showErrorBox(