forked from mixmix/infinite-game
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
56 lines (43 loc) · 1.39 KB
/
index.js
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
const { app, ipcMain } = require('electron')
const { join } = require('path')
const Menu = require('./lib/electron/menu')
const Server = require('./lib/electron/process/server')
const UI = require('./lib/electron/process/ui')
const config = require('./config').create().config.sync.load()
const plugins = ['ssb-about', 'ssb-backlinks', 'ssb-private', 'ssb-query', 'ssb-suggest']
const state = {
windows: {
server: null,
ui: null
},
quitting: false
}
app.on('ready', () => {
Menu()
app.on('before-quit', () => { state.quitting = true })
ipcMain.on('open-background-devtools', () => {
if (state.windows.server) state.windows.server.webContents.openDevTools({ detach: true })
})
state.windows.server = Server(config, plugins)
ipcMain.once('server-started', () => {
state.windows.ui = UI(join(__dirname, 'src/index'), { width: 1024, height: 768 }, config)
state.windows.ui.on('close', (e) => {
if (!state.quitting && process.platform === 'darwin') {
e.preventDefault()
state.windows.ui.hide()
}
})
state.windows.ui.on('closed', () => {
state.windows.ui = null
if (process.platform !== 'darwin') app.quit()
})
})
})
ipcMain.on('server-close', () => {
if (!state.windows.server) return
state.windows.server.webContents.send('server-close')
})
ipcMain.on('server-closed', () => {
state.windows.ui.hide()
app.quit()
})