This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
93 lines (80 loc) · 2.21 KB
/
index.mjs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import path from 'path'
import electron from 'electron'
import settings from 'electron-settings'
const { app, BrowserWindow, ipcMain, dialog } = electron
let consoleWindow, presenterWindow, state
const saveState = (s) => {
state = s
settings.set('state', s)
console.log('saveState', s)
}
const createWindow = (name) => {
const thisWindow = new BrowserWindow({
width: name === 'console' ? 540 : 800,
height: 600,
icon: path.resolve(app.getAppPath(), 'web/assets/icons/electron-tracker.png'),
webPreferences: {
preload: path.resolve(app.getAppPath(), `${name}-preload.cjs`),
nodeIntegration: true
}
})
thisWindow.menuBarVisible = false
return thisWindow
}
const createConsoleWindow = () => {
consoleWindow = createWindow('console')
consoleWindow.loadFile(path.resolve(app.getAppPath(), 'web/console.html'))
consoleWindow.on('close', app.exit)
}
const createPresenterWindow = () => {
if (presenterWindow){
presenterWindow.hide()
presenterWindow.show()
return
}
presenterWindow = createWindow('presenter')
presenterWindow.loadFile(path.resolve(app.getAppPath(), 'web/presenter.html'))
presenterWindow.on('close', () => {
presenterWindow = null
})
}
const broadcastState = (_event, s, all) => {
if (typeof all === 'undefined') all = false
if (all) {
consoleWindow.webContents.send('console:state', s)
} else {
saveState(s)
}
if (presenterWindow) {
presenterWindow.webContents.send('presenter:state', s)
}
}
const broadcastFiles = (files, all) => {
consoleWindow.webContents.send('console:files', files)
}
app.on('ready', () => {
createConsoleWindow()
settings.get('state').then((s) => {
if (s == null) {
s = {
campaigns: ["default"]
}
}
state = s
broadcastState(null, s, true)
})
})
ipcMain.handle('openFiles', () => dialog.showOpenDialog({properties: ['openFile', 'multiSelections']}))
ipcMain.on('openPresenter', createPresenterWindow)
ipcMain.on('setState', broadcastState)
ipcMain.handle('getState', () => state)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (consoleWindow === null) {
createConsoleWindow()
}
})