fix: 修复 preload 路径 (.mjs 而不是 .js)

- electron-vite v3 输出 .mjs 文件
- 更新 preload 路径为 index.mjs
- 这是 window.electronAPI undefined 的根本原因
This commit is contained in:
2026-07-04 20:10:58 +08:00
parent d488612c27
commit 7f2c753470
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -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,
+3
View File
@@ -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, {