-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
124 lines (99 loc) · 3.38 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const {app, BrowserWindow} = require('electron');
const {ipcMain} = require('electron');
const {path} = require('path');
let mainWindow;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
app.quit();
});
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1052, height: 650, frame: false,resizable:false});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/View/HTML/configuration-page.html');
//send server configuration to main page
/*Set up events*/
/*Set Server Configuration*/
ipcMain.once('set-up-server-configuration',(event,arg) => {
const win = BrowserWindow.fromId(2);
win.webContents.on('did-finish-load',function(){
win.webContents.send('set-up-server',arg);
});
/*Update players information*/
ipcMain.on('players-information',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.on('did-finish-load',function(){
win.webContents.send('players-information',arg);
});
win.webContents.send('players-information',arg);
});
/*Update Header Board*/
ipcMain.on('header-update',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.send('header-update',arg);
});
/*Update Ranking To Player Board*/
ipcMain.on('alarm-ranking',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.send('alarm-ranking',arg);
});
/*------------*/
ipcMain.on('alarm-clearing',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.send('alarm-clearing',arg);
});
ipcMain.on('change-show-mode',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.send('change-show-mode',arg);
});
ipcMain.on('time-set-up',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.send('time-set-up',arg);
});
ipcMain.on('time-stop',(event,arg) => {
var id = arg.WD_ID;
const win = BrowserWindow.fromId(id);
win.webContents.send('time-stop',arg);
});
/*-----------------*/
});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow = null;
});
});
/*
const os = require('os');
const NUMBER_OF_CORES = os.cpus().length;
let startTime = process.hrtime();
let startUsage = process.cpuUsage();
setInterval(() => {
var now = Date.now();
while(Date.now() - now < 500);
const newTime = process.hrtime();
const newUsage = process.cpuUsage();
const elapTime = process.hrtime(startTime);
const elapUsage = process.cpuUsage(startUsage);
startUsage = newUsage;
startTime = newTime;
const elapTimeMS = hrtimeToMS(elapTime);
const elapUserMS = elapUsage.user / 1000;
const elapSystMS = elapUsage.system / 1000;
const cpuPercent = (100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CORES).toFixed(1) + "%";
console.log('elapsed time ms : ',elapTimeMS);
console.log('elapsed user ms : ',elapUserMS);
console.log('elapsed system ms : ',elapSystMS);
console.log('cpu percent : ',cpuPercent,'\n');
},1000);
function hrtimeToMS(hrtime){
return hrtime[0] * 1000 + hrtime[1] / 1000000;
}
*/