-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.js
100 lines (91 loc) · 2.44 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// app - Module to control application life.
// BrowserWindow - Module to create native browser window.
// const electron = require('electron');
const { app, BrowserWindow, Menu, shell } = require('electron');
const path = require('path');
const os = require('os');
function createWindow() {
const mainWindow = new BrowserWindow({
width: 500,
height: 700,
minWidth: 500,
minHeight: 700,
title: 'p5.serialcontrol',
icon: `${__dirname}/../assets/icons/png/[email protected]`,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
preload: path.join(__dirname, 'preload.js'),
},
});
mainWindow.loadFile('index.html');
mainWindow.webContents.on('did-finish-load', () => {
let interfaces = os.networkInterfaces();
let addresses = [];
for (let k in interfaces) {
for (let k2 in interfaces[k]) {
let address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}
mainWindow.webContents.send('send-ip', `${addresses}`);
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
let template = [
{
label: app.getName(),
submenu: [
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
selector: 'copy:',
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
selector: 'paste:',
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
selector: 'selectAll:',
},
{
label: 'Toggle Developer Tools',
accelerator:
process.platform === 'darwin'
? 'Alt+Command+I'
: 'Ctrl+Shift+I',
click(item, focusedWindow) {
if (focusedWindow)
focusedWindow.webContents.toggleDevTools();
},
},
{
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click: function () {
app.quit();
},
},
],
},
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
});
app.on('window-all-closed', function () {
app.quit();
});
let serialserver = require('p5.serialserver');
serialserver.start(8081);
console.log('p5.serialserver is running');