From 7f2c75347028a2c8dc423b7b3c1bbe308852fa4f Mon Sep 17 00:00:00 2001 From: Jokul Date: Sat, 4 Jul 2026 20:10:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20preload=20=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=20(.mjs=20=E8=80=8C=E4=B8=8D=E6=98=AF=20.js)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - electron-vite v3 输出 .mjs 文件 - 更新 preload 路径为 index.mjs - 这是 window.electronAPI undefined 的根本原因 --- src/main/index.ts | 2 +- src/renderer/src/stores/connection.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index ac456f6..d107009 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -15,7 +15,7 @@ function createWindow(): void { title: 'JRedisDesktop', backgroundColor: nativeTheme.shouldUseDarkColors ? '#0f0f1a' : '#f8fafc', webPreferences: { - preload: join(__dirname, '../preload/index.js'), + preload: join(__dirname, '../preload/index.mjs'), contextIsolation: true, nodeIntegration: false, sandbox: false, diff --git a/src/renderer/src/stores/connection.ts b/src/renderer/src/stores/connection.ts index 7479fc8..5ea0058 100644 --- a/src/renderer/src/stores/connection.ts +++ b/src/renderer/src/stores/connection.ts @@ -126,6 +126,9 @@ export const useConnectionStore = defineStore('connection', () => { async function testConnection(opts: { host: string; port: number; auth?: string; username?: string; tls?: boolean }): Promise<{ success: boolean; error?: string }> { + if (!window.electronAPI) { + return { success: false, error: 'Electron API not ready' } + } const testId = `test_${Date.now()}` try { const result = await window.electronAPI.redis.connect(testId, {