-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (48 loc) · 1.47 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
const {app, BrowserWindow, ipcMain, globalShortcut} = require('electron')
const path = require('path')
const url = require('url')
const SerialPort = require('serialport')
const Readline = SerialPort.parsers.Readline
const port = new SerialPort('COM6')
const parser = new Readline()
let win
function createWindow () {
win = new BrowserWindow({width: 350, height: 550})
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
win.on('closed', () => {
win = null
})
win.webContents.on('did-finish-load', () => {
win.webContents.send('loaded')
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit()}})
app.on('activate', () => {if (win === null) {createWindow()}})
ipcMain.on('done', (event, X) => {
console.log(X)
})
ipcMain.on('confirmed-load', (event) => {
console.log("App Loaded!")
port.pipe(parser);
parser.on('data', (data) => {
// console.log(data)
args = data.split(";")
//console.log(args)
if(args[0].charAt(0) == "S") return
let [x,y,w,h] = args
event.sender.send('newData', x, y, w, h)
console.log(`CenterX:${x} -=- CenterY:${y} -=- Width:${w} -=- Height:${h}`)
// if(data.charAt(0) == "X") {
// let X = data.split("X")[1]
// event.sender.send('newX', X)
// } else if(data.charAt(0) == "Y") {
// let Y = data.split("Y")[1]
// event.sender.send('newY', Y)
//}
});
})