From 4acdad6535951a5289a25d39ecd8bc2d11f6e527 Mon Sep 17 00:00:00 2001 From: dream_pep Date: Sat, 5 Sep 2026 20:36:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(paths):=20=E9=87=8D=E6=9E=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DLinux=E6=89=93=E5=8C=85=E7=89=88=E5=86=99=E5=85=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适配Linux AppImage打包场景,将数据基准目录改为userData以解决只读目录无法写入的问题;重构路径解析相关函数,添加详细注释并优化代码结构。 --- electron/core/paths.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/electron/core/paths.ts b/electron/core/paths.ts index 2c9c6ae..7de69a2 100644 --- a/electron/core/paths.ts +++ b/electron/core/paths.ts @@ -1,17 +1,30 @@ // 路径归一化:相对 gameDir(默认 `.minecraft`)在打包后依赖进程 cwd,不可靠。 -// 统一按与 runStartupChecks 一致的基准解析(打包 → exe 目录;开发 → 项目根)。 +// 统一按与 runStartupChecks 一致的基准解析(见 dataBasePath)。 import * as path from 'path'; import electron from 'electron'; const { app } = electron; -function baseDataPath(): string { - if (app.isPackaged) { - return path.dirname(app.getPath('exe')); +/** + * 数据基准目录(游戏数据 `.minecraft` 等相对路径的解析根): + * - 开发模式 → 项目根 + * - Linux / AppImage → userData:exe 目录是只读挂载(/tmp/.mount_*),无法写入 + * - Windows 打包 → exe 目录(沿用历史行为) + */ +export function dataBasePath(): string { + if (!app.isPackaged) { + return path.join(__dirname, '..', '..'); } - return path.join(__dirname, '..', '..'); + if (process.platform === 'linux') { + return app.getPath('userData'); + } + return path.dirname(app.getPath('exe')); } -/** 相对路径 → 绝对(基准 = exe 目录/项目根);绝对路径原样返回 */ +function baseDataPath(): string { + return dataBasePath(); +} + +/** 相对路径 → 绝对(基准 = dataBasePath);绝对路径原样返回 */ export function resolveGamePath(gamePath: string): string { if (!gamePath || path.isAbsolute(gamePath)) { return gamePath;