fix: 修复打包版背景图黑屏问题,重构数据路径逻辑

新增背景图路径归一化函数,将旧版使用的绝对路径 `/background.png` 转换为适配全环境的正确相对路径;重构Electron主进程的数据基准路径计算逻辑,修复Linux/AppImage打包版的只读目录限制
This commit is contained in:
2026-09-05 20:35:59 +08:00
parent caf52b9a3d
commit 3b627389c9
2 changed files with 8 additions and 4 deletions
+3 -3
View File
@@ -20,6 +20,7 @@ import { saveConfig, configExists, getConfig, flushConfig, configPath } from './
import { findCachedBackgroundRaw, optimizeBackgroundFile, recoverBackgroundFromDataUrl } from './core/background-image';
import { registerResourceSchemePrivileges, registerResourceProtocol } from './resource-protocol';
import { createLogger, setDebugModeProvider, installIpcLogging, registerRendererLogBridge } from './core/logger';
import { dataBasePath } from './core/paths';
const { app } = electron;
@@ -73,9 +74,8 @@ function migrateLegacyFiles(): void {
// Startup checks: .minecraft dir + config file + first launch detection
function runStartupChecks(): { isFirstLaunch: boolean; config: ReturnType<typeof getConfig> } {
const dataPath = app.isPackaged
? path.dirname(app.getPath('exe'))
: path.join(__dirname, '..');
// 数据基准:开发→项目根;Windows 打包→exe 目录;Linux/AppImage→userDataexe 目录是只读挂载)
const dataPath = dataBasePath();
// 1. Ensure .minecraft directory exists
const minecraftDir = path.join(dataPath, '.minecraft');
+5 -1
View File
@@ -23,6 +23,10 @@ const DEFAULT: { type: BackgroundType; image: string; blur: number; opacity: num
opacity: 1,
};
/** 旧版主进程默认值用的绝对路径 /background.pngdev 可显示,打包 file:// 下指向文件系统根→黑屏)。
* 统一归一化为渲染端 DEFAULT_BGBASE_URL 相对路径,dev/打包均正确)。 */
const normalizeDefaultBg = (url: string): string => (url === "/background.png" ? DEFAULT_BG : url);
export const useBackgroundStore = create<BackgroundState>((set) => ({
...DEFAULT,
@@ -56,7 +60,7 @@ export function syncBackgroundFromConfig() {
const bg = useConfigStore.getState().config.background;
useBackgroundStore.setState({
type: bg.bgType as BackgroundType,
image: bg.image,
image: normalizeDefaultBg(bg.image),
blur: bg.blur,
opacity: bg.opacity / 100,
});