a4412793f4
Introduce pack-bootstrap chunk, ZipArchive-based PackService with progress IPC, book registry import helpers, and IT-PACK-01 / IT-ALL-02 integration tests. Co-authored-by: Cursor <cursoragent@cursor.com>
96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
import { app, BrowserWindow, ipcMain } from 'electron'
|
|
import { existsSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { IPC } from '../shared/ipc-channels'
|
|
import { getShortcutManager, getSnapshotService, getNetworkMonitor, registerIpc } from './ipc/register'
|
|
import { closeAllBookDbs } from './db/connection'
|
|
|
|
if (process.env.BILIN_E2E === '1' && process.env.BILIN_E2E_USER_DATA) {
|
|
app.setPath('userData', process.env.BILIN_E2E_USER_DATA)
|
|
}
|
|
|
|
let mainWindow: BrowserWindow | null = null
|
|
|
|
function preloadPath(): string {
|
|
const dir = join(__dirname, '../preload')
|
|
const mjs = join(dir, 'index.mjs')
|
|
if (existsSync(mjs)) return mjs
|
|
return join(dir, 'index.js')
|
|
}
|
|
|
|
function createWindow(): void { mainWindow = new BrowserWindow({
|
|
width: 1280,
|
|
height: 800,
|
|
minWidth: 960,
|
|
minHeight: 600,
|
|
frame: false,
|
|
titleBarStyle: 'hidden',
|
|
webPreferences: {
|
|
preload: preloadPath(),
|
|
contextIsolation: true,
|
|
nodeIntegration: false
|
|
}
|
|
})
|
|
|
|
if (process.env.ELECTRON_RENDERER_URL) {
|
|
mainWindow.loadURL(process.env.ELECTRON_RENDERER_URL)
|
|
} else {
|
|
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
|
}
|
|
|
|
if (process.env.BILIN_E2E === '1') {
|
|
mainWindow.webContents.setDevToolsEnabled(false)
|
|
}
|
|
|
|
mainWindow.on('closed', () => {
|
|
mainWindow = null
|
|
})
|
|
|
|
getShortcutManager()?.setWindow(mainWindow)
|
|
getNetworkMonitor()?.start(() => mainWindow)
|
|
}
|
|
|
|
app.whenReady().then(async () => {
|
|
const { books, settings } = registerIpc()
|
|
const { bootstrapImportHandlers } = await import('./import-bootstrap.js')
|
|
bootstrapImportHandlers(books)
|
|
const { bootstrapPackHandlers } = await import('./pack-bootstrap.js')
|
|
bootstrapPackHandlers(books, settings)
|
|
|
|
ipcMain.handle(IPC.WINDOW_MINIMIZE, (event) => {
|
|
BrowserWindow.fromWebContents(event.sender)?.minimize()
|
|
})
|
|
ipcMain.handle(IPC.WINDOW_MAXIMIZE, (event) => {
|
|
const win = BrowserWindow.fromWebContents(event.sender)
|
|
if (!win) return
|
|
if (win.isMaximized()) win.unmaximize()
|
|
else win.maximize()
|
|
})
|
|
ipcMain.handle(IPC.WINDOW_CLOSE, (event) => {
|
|
BrowserWindow.fromWebContents(event.sender)?.close()
|
|
})
|
|
|
|
createWindow()
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
getShortcutManager()?.unregisterAll()
|
|
getNetworkMonitor()?.stop()
|
|
getSnapshotService()?.stopAll()
|
|
closeAllBookDbs()
|
|
if (process.platform !== 'darwin') app.quit()
|
|
})
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
})
|
|
|
|
app.on('before-quit', () => {
|
|
getSnapshotService()?.stopAll()
|
|
})
|
|
|
|
app.on('will-quit', () => {
|
|
getShortcutManager()?.unregisterAll()
|
|
getNetworkMonitor()?.stop()
|
|
})
|