fix(ipc): add support for portable executable paths on Windows (#8274)

This commit is contained in:
beyondkmp 2025-07-18 18:54:31 +08:00 committed by GitHub
parent 5488c950aa
commit d0c375aa0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import { arch } from 'node:os'
import path from 'node:path'
import { loggerService } from '@logger'
import { isLinux, isMac, isWin } from '@main/constant'
import { isLinux, isMac, isPortable, isWin } from '@main/constant'
import { getBinaryPath, isBinaryExists, runInstallScript } from '@main/utils/process'
import { handleZoomFactor } from '@main/utils/zoom'
import { UpgradeChannel } from '@shared/config/constant'
@ -335,6 +335,12 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
options.args.unshift('--appimage-extract-and-run')
}
if (isWin && isPortable) {
options = options || {}
options.execPath = process.env.PORTABLE_EXECUTABLE_FILE
options.args = options.args || []
}
app.relaunch(options)
app.exit(0)
})

View File

@ -4,7 +4,7 @@ import os from 'node:os'
import path from 'node:path'
import { loggerService } from '@logger'
import { isLinux, isPortable } from '@main/constant'
import { isLinux, isPortable, isWin } from '@main/constant'
import { audioExts, documentExts, imageExts, MB, textExts, videoExts } from '@shared/config/constant'
import { FileMetadata, FileTypes } from '@types'
import { app } from 'electron'
@ -72,6 +72,10 @@ function getAppDataPathFromConfig() {
executablePath = path.join(path.dirname(process.env.APPIMAGE), 'cherry-studio.appimage')
}
if (isWin && isPortable) {
executablePath = path.join(process.env.PORTABLE_EXECUTABLE_DIR || '', 'cherry-studio-portable.exe')
}
let appDataPath = null
// 兼容旧版本
if (config.appDataPath && typeof config.appDataPath === 'string') {
@ -108,6 +112,11 @@ export function updateAppDataConfig(appDataPath: string) {
executablePath = path.join(path.dirname(process.env.APPIMAGE), 'cherry-studio.appimage')
}
// 如果是 Windows 可移植版本,则使用 PORTABLE_EXECUTABLE_FILE 环境变量
if (isWin && isPortable) {
executablePath = path.join(process.env.PORTABLE_EXECUTABLE_DIR || '', 'cherry-studio-portable.exe')
}
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify({ appDataPath: [{ executablePath, dataPath: appDataPath }] }, null, 2))
return