-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
153 lines (121 loc) · 3.74 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const { app, BrowserWindow, screen, ipcMain } = require('electron')
const { exec } = require('child_process');
const path = require('node:path')
// var Gpio = require('onoff').Gpio;
// var pushButton = new Gpio(2, 'in', 'falling');
const express = require('express');
const http = require('http')
const cors = require('cors');
const port = 8999;
const ekspres = express();
ekspres.use(cors());
app.disableHardwareAcceleration()
function enableWebServer() {
console.log("Enabling Web Server ....")
server = ekspres.listen(port, () => {
console.log(`Web Server Enabled! Listening at port: ${port}`)
// callback(null, true)
});
}
enableWebServer();
let doOnce = false
const createRaspApp = (x, y) => {
const win = new BrowserWindow({
width: 600,
height: 1024,
x: x,
y: y,
kiosk: true,
autoHideMenuBar: true,
frame: false,
fullscreen: true,
alwaysOnTop: true,
resizable: false,
webPreferences: {
preload: path.join(__dirname, 'RaspPreload.js')
}
})
win.loadFile('RaspApp.html')
return win
}
const createTVApp = (x, y) => {
const win = new BrowserWindow({
width: 1080,
height: 1920,
x: x,
y: y,
// kiosk: true,
kiosk: true,
autoHideMenuBar: true,
frame: false,
fullscreen: true,
alwaysOnTop: true,
resizable: false,
webPreferences: {
preload: path.join(__dirname, 'TvPreload.js')
}
})
win.loadFile('TvApp.html')
return win
}
ipcMain.on('finger', (event) => {
console.log("FINGER!!!")
})
app.whenReady().then(() => {
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
// const displays = screen.getAllDisplays()
const primaryDisplay = screen.getPrimaryDisplay()
const secondDisplay = screen.getAllDisplays().find(d => d.id != primaryDisplay.id)
console.log(primaryDisplay)
console.log(secondDisplay)
// const primaryBounds = primaryDisplay.bounds
// const secondBounds = secondDisplay.bounds
const tv = createTVApp(600, 0)
const rasp = createRaspApp(0, 0)
// const rasp = createRaspApp(primaryBounds.x, primaryBounds.y) // for dev
// setTimeout((() => {
// tv.webContents.send('coin')
// rasp.webContents.send('coin')
// }), 3000)
//na malym trwa losowanie
//losowanie zakończone
ipcMain.on('finger', (event) => {
tv.webContents.send('finger')
})
ipcMain.on('print', (event, name) => {
const toPrint = name.name
// 'lpr -o fit-to-page ' + toPrint,
exec('lprm - && lpr -o fit-to-page ' + toPrint, (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return;
}
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
console.log("PRINTING!!! " + toPrint)
})
tv.webContents.on('console-message', (event, level, message, line, sourceId) => {
console.log(message + " " + sourceId + " (" + line + ")");
});
rasp.webContents.on('console-message', (event, level, message, line, sourceId) => {
console.log(message + " " + sourceId + " (" + line + ")");
});
ekspres.get("/gotMoney", (req, res) => {
if (!doOnce) {
console.log('Got it!')
tv.webContents.send('coin')
rasp.webContents.send('coin')
doOnce = true
}
setTimeout(() => {
doOnce = false
}, 1500)
return res.json({ "status": true })
})
})