-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
67 lines (52 loc) · 1.25 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
const electron = require('electron')
const path = require('path')
const url = require('url')
const server = require('http').createServer()
const io = require('socket.io')(server)
const PythonShell = require('python-shell')
const pyshell = new PythonShell('lib/FaceRecognitionAPI/script.py')
process.env.GOOGLE_API_KEY = 'AIzaSyAxEd1c2fuK7zBlHV6ENZ1Ua2uqfP1Yfl8'
const {app, BrowserWindow} = electron
let win
const createWindow = () => {
win = new BrowserWindow({
fullscreen: true
})
win.loadURL(url.format({
pathname: path.join(__dirname, 'build/index.html'),
protocol: 'file:',
slashes: true
}))
win.on('closed', () => {
win = null
})
win.webContents.openDevTools()
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})
// Socket.io configuration
io.on('connection', client => {
client.on('event', data => {})
client.on('disconnect', () => {})
})
server.listen(3000)
pyshell.on('message', message => {
try {
message = JSON.parse(message)
io.emit('message', message)
} catch (e) {
// Not JSON, don't parse
}
})
pyshell.end(err => {
if (err) throw err
})