This repository was archived by the owner on Jan 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderCPU.js
More file actions
136 lines (115 loc) · 4.51 KB
/
renderCPU.js
File metadata and controls
136 lines (115 loc) · 4.51 KB
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
const os = require("os");
const osUtils = require('os-utils');
const Chart = require("chart.js");
const diskspace = require('diskspace');
const $ = require('jquery');
const ipc = require('electron').ipcRenderer;
var cpuInfo = os.cpus();
var plattform = os.platform();
//ELEMENT CONFIG
var ctxcpu = document.getElementById("cpuChart").getContext('2d');
var Sidebar = document.getElementById("Sidebar");
var overlayBg = document.getElementById("myOverlay");
var menuButton = document.getElementById("MenuButton");
var FullscreenButton = document.getElementById("FullscreenButton");
//TABLE CONFIG
var infoofthismodelrow = document.createElement("TR");
var infoofthisspeedrow = document.createElement("TR");
var TimesHeadingrow = document.createElement("TR");
var infoofthistimerow_user = document.createElement("TR");
var infoofthistimerow_system = document.createElement("TR");
var infoofthistimerow_irq = document.createElement("TR");
var infoofthistimerow_idle = document.createElement("TR");
//TABLE INITIALISATION
cpuInfo.forEach(function(val, index) {
var infoofthismodel = document.createElement("TH");
infoofthismodel.innerHTML = val.model;
infoofthismodelrow.appendChild(infoofthismodel);
var infoofthisspeed = document.createElement("TD");
infoofthisspeed.innerHTML = "Speed: " + val.speed + "Hz (" + (val.speed / 1000).toFixed(1) + "GHz)";
infoofthisspeedrow.appendChild(infoofthisspeed);
var TimesHeading = document.createElement("TH");
TimesHeading.innerHTML = "Times";
TimesHeadingrow.appendChild(TimesHeading);
var infoofthistime = document.createElement("TD");
infoofthistime.innerHTML = "User: " + val.times.user + "ms";
infoofthistimerow_user.appendChild(infoofthistime);
infoofthistime = document.createElement("TD");
infoofthistime.innerHTML = "System: " + val.times.sys + "ms";
infoofthistimerow_system.appendChild(infoofthistime);
infoofthistime = document.createElement("TD");
infoofthistime.innerHTML = "Irq: " + val.times.irq + "ms";
infoofthistimerow_irq.appendChild(infoofthistime);
infoofthistime = document.createElement("TD");
infoofthistime.innerHTML = "Idle: " + val.times.idle + "ms";
infoofthistimerow_idle.appendChild(infoofthistime);
});
//INSERT TABLE
document.getElementById("Info").appendChild(infoofthismodelrow);
document.getElementById("Info").appendChild(infoofthisspeedrow);
document.getElementById("Info").appendChild(TimesHeadingrow);
document.getElementById("Info").appendChild(infoofthistimerow_user);
document.getElementById("Info").appendChild(infoofthistimerow_system);
document.getElementById("Info").appendChild(infoofthistimerow_irq);
document.getElementById("Info").appendChild(infoofthistimerow_idle);
//PARTS OF THIS FUNCTON WILL BE PERFORMED CONSTANTLY
function performConstant() {
var cpuUsage = process.cpuUsage();
osUtils.cpuUsage(function(v) {
document.getElementById("cpuUsagePercent").innerHTML = (v * 100).toFixed(2);
var cpuChart = new Chart(ctxcpu, {
type: 'pie',
data: {
labels: ["Used", "Free"],
datasets: [{
data: [(v * 100).toFixed(2), (100 - (v * 100)).toFixed(2)],
backgroundColor: [
'rgba(255, 0, 0, 1)',
'rgba(0, 225, 0, 1)'
],
borderColor: [
'rgba(255, 0, 0, 1)',
'rgba(0, 225, 0, 1)'
]
}]
},
options: {
animation: false,
responsive: false,
legend: {
display: false
}
}
});
});
}
//INITIALISATE THE TIMER
//RUN THE FUNCTION EVERY 350 MS
var Timer = setInterval(function() {
performConstant();
}, 500);
function w3_open() {
if (Sidebar.style.display === 'block') {
Sidebar.style.display = 'none';
overlayBg.style.display = "none";
} else {
Sidebar.style.display = 'block';
overlayBg.style.display = "block";
}
}
function w3_close() {
Sidebar.style.display = "none";
overlayBg.style.display = "none";
}
//EVENT LISTENER
overlayBg.addEventListener('click', function(clickEvent) {
w3_close();
console.log("Clicked Overlay!");
});
menuButton.addEventListener('click', function(clickEvent) {
w3_open();
console.log("Clicked Menu Button!");
});
FullscreenButton.addEventListener('click', function(clickEvent) {
ipc.send("togglefullscreen");
});