-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
71 lines (60 loc) · 1.86 KB
/
Copy pathindex.ts
File metadata and controls
71 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { app, BrowserWindow } from 'electron'
import { join } from 'path'
import { DatabaseManager } from './database'
import { Indexer } from './indexer'
import { PtyManager } from './pty-manager'
import { registerIpcHandlers } from './ipc-handlers'
if (process.env.ELECTRON_RENDERER_URL) {
app.commandLine.appendSwitch('remote-debugging-port', '9222')
}
const mainWindowRef = { current: null as BrowserWindow | null }
let db: DatabaseManager
let indexer: Indexer
let ptyManager: PtyManager
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 900,
minHeight: 600,
title: 'SessionManager',
titleBarStyle: 'hiddenInset',
trafficLightPosition: { x: 16, y: 16 },
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
contextIsolation: true,
nodeIntegration: false
}
})
mainWindowRef.current = win
if (process.env.ELECTRON_RENDERER_URL) {
win.loadURL(process.env.ELECTRON_RENDERER_URL)
} else {
win.loadFile(join(__dirname, '../renderer/index.html'))
}
}
app.whenReady().then(async () => {
const dbPath = join(app.getPath('userData'), 'session-manager.db')
db = new DatabaseManager(dbPath)
db.initialize()
indexer = new Indexer(db)
ptyManager = new PtyManager()
createWindow()
registerIpcHandlers(db, indexer, ptyManager, mainWindowRef)
// Initial index in background so window opens immediately
indexer.indexAll().then(() => {
mainWindowRef.current?.webContents.send('index-ready')
})
setInterval(() => {
indexer.indexAll().then(() => {
mainWindowRef.current?.webContents.send('index-ready')
})
}, 5 * 60 * 1000)
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
ptyManager?.killAll()
if (process.platform !== 'darwin') app.quit()
})