Files
JRedisDesktop/electron/main/index.ts
T
Jokul 405dfa77c4 feat: auto-updater integration
- Install electron-updater
- New updater.ts: check/download/install with progress events
- IPC: updater:check, updater:download, updater:install, updater:status
- Preload bridge for updater API
- electron-builder publish config (github provider)
- Fix build files path: out -> electron-dist
- i18n keys for updater notifications (zh-CN + en)
2026-07-05 22:13:25 +08:00

67 lines
1.7 KiB
TypeScript

// src/main/index.ts
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()
})