store downloaded apps under user app directory
This commit is contained in:
+25
-8
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user