refactor: 迁移至 electron-vite 官方推荐目录结构
- electron/* -> src/main/* (主进程) - electron/preload.ts -> src/preload/index.ts (预加载) - src/electron-api.d.ts -> src/preload/index.d.ts (类型声明) - src/* -> src/renderer/src/* (渲染进程) - src/index.html -> src/renderer/index.html - electron.vite.config.ts 简化为自动入口检测 (零配置) - tsconfig.app.json -> tsconfig.web.json, 更新 includes/paths - 构建产物 dist-electron/ -> out/ (修复 main/preload 输出覆盖 bug) - 更新 package.json main 字段 + electron-builder files - 更新 .gitignore + eslint ignores - 更新 AGENTS.md 架构文档
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { app, BrowserWindow, nativeTheme, nativeImage } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { restoreAndTrack } from './win-state'
|
||||
import { registerIpcHandlers } from './ipc-handlers'
|
||||
import { initUpdater } from './updater'
|
||||
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
|
||||
function getIconPath(): string {
|
||||
return join(__dirname, '../../build/icons/icon_256.png')
|
||||
}
|
||||
|
||||
function createWindow(): void {
|
||||
const iconPath = getIconPath()
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
minWidth: 900,
|
||||
minHeight: 600,
|
||||
title: 'JRedisDesktop',
|
||||
icon: nativeImage.createFromPath(iconPath),
|
||||
backgroundColor: nativeTheme.shouldUseDarkColors ? '#0f0f1a' : '#f8fafc',
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.mjs'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
sandbox: false,
|
||||
},
|
||||
frame: false,
|
||||
titleBarStyle: 'hidden',
|
||||
transparent: true,
|
||||
})
|
||||
|
||||
// Linux taskbar icon
|
||||
if (process.platform === 'linux' && mainWindow) {
|
||||
mainWindow.setIcon(nativeImage.createFromPath(iconPath))
|
||||
}
|
||||
|
||||
restoreAndTrack(mainWindow)
|
||||
|
||||
if (process.env.ELECTRON_RENDERER_URL) {
|
||||
mainWindow.loadURL(process.env.ELECTRON_RENDERER_URL)
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
|
||||
mainWindow.on('closed', () => { mainWindow = null })
|
||||
|
||||
nativeTheme.on('updated', () => {
|
||||
mainWindow?.webContents.send('theme:os-updated', nativeTheme.shouldUseDarkColors)
|
||||
})
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
registerIpcHandlers()
|
||||
createWindow()
|
||||
initUpdater(mainWindow!)
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => { app.quit() })
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
Reference in New Issue
Block a user