-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathindex.ts
More file actions
78 lines (65 loc) · 1.99 KB
/
index.ts
File metadata and controls
78 lines (65 loc) · 1.99 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
72
73
74
75
76
77
78
import { app, BrowserWindow, ipcMain, Menu } from 'electron'
import path from 'path'
import os from 'os'
import { store } from './store'
import { ApiServer } from './services/api/server'
import { createDb } from './services/db'
import { debounce } from 'lodash'
import { subscribeToChannels } from './services/ipc'
import { mainMenu } from './menu/main'
import { subscribeToDialog } from './services/ipc/dialog'
const isDev = process.env.NODE_ENV === 'development'
createDb()
const apiServer = new ApiServer()
subscribeToChannels()
subscribeToDialog()
function createWindow () {
const bounds = store.app.get('bounds')
const mainWindow = new BrowserWindow({
width: 1000,
height: 600,
...bounds,
titleBarStyle: 'hidden',
webPreferences: {
preload: path.resolve(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: true,
webSecurity: false
}
})
Menu.setApplicationMenu(mainMenu)
if (isDev) {
const rendererPort = process.argv[2]
mainWindow.loadURL(`http://localhost:${rendererPort}`)
} else {
mainWindow.loadFile(path.resolve(app.getAppPath(), 'renderer/index.html'))
}
mainWindow.on('resize', () => storeBounds(mainWindow))
mainWindow.on('move', () => storeBounds(mainWindow))
}
const storeBounds = debounce((mainWindow: BrowserWindow) => {
store.app.set('bounds', mainWindow.getBounds())
}, 300)
app.whenReady().then(async () => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
ipcMain.handle('main:restart-api', () => {
apiServer.restart()
})
ipcMain.on('request-info', event => {
event.sender.send('request-info', {
version: app.getVersion(),
arch: os.arch(),
platform: process.platform
})
})