aac51bf183
Implement schema v2 migration, outline/setting/inspiration CRUD, unified TipTap editing, reference panel with mentions, FTS global search, chapter version history, writing landmarks, word frequency analysis, light theme contrast fixes, and full unit/E2E test coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.1 KiB
TypeScript
85 lines
2.1 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, 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'))
|
|
}
|
|
|
|
mainWindow.on('closed', () => {
|
|
mainWindow = null
|
|
})
|
|
|
|
getShortcutManager()?.setWindow(mainWindow)
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
registerIpc()
|
|
|
|
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()
|
|
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()
|
|
})
|