-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (64 loc) · 1.7 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { app, BrowserWindow, ipcMain } = require('electron')
const nano = require('./lib')
const start = (webContents) => {
// Init nano lib
const sendEvent = (channel, args) => {
if ((typeof webContents.send) === 'function') {
webContents.send(channel, args)
} else {
console.log('can not send event')
}
}
const listenEvent = (channel, callable) => {
ipcMain.on(channel, function (event, arg) {
callable(arg, event)
})
}
const nanoleaf = new nano.nanoManager(
new nano.IpFinder(),
new nano.ConfigLoader(__dirname),
new nano.beatsaberAdaptater(),
sendEvent,
listenEvent,
)
// temp
setTimeout(() => {
nanoleaf.start()
}, 500);
}
const createWindow = () => {
const mainWindow = new BrowserWindow({
width:1400,
height:900,
resizable:false,
minimizable : false,
maximizable : false,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
},
frame:false,
title:'nanoleaf',
})
mainWindow.loadFile('./view/main/index.html')
.then(() => {
mainWindow.webContents.openDevTools()
start(mainWindow.webContents)
})
.catch((err) => console.error(err))
}
app.allowRendererProcessReuse = false;
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
BrowserWindow.getAllWindows().length === 0 && createWindow()
})
})
app.on('window-all-closed', function () {
process.platform !== 'darwin' && app.quit()
})
ipcMain.on('close', (evt, arg) => {
app.quit();
});