-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
106 lines (98 loc) · 2.46 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
const { Extension, log, INPUT_METHOD, PLATFORMS } = require('deckboard-kit');
const { Query } = require('node-wmi');
const CATEGORIZATION = {
load: {
'Memory': 'ram',
'CPU Total': 'cpu',
'GPU Core': 'gpu'
},
temperature: {
'CPU Package': 'cpu',
'GPU Core': 'gpu'
}
}
const SUFFIX = {
load: '%',
temperature: '°C'
}
const DEFAULT_VALUE = {
'hw-load-cpu': '-%',
'hw-load-gpu': '-%',
'hw-load-ram': '-%',
'hw-temperature-cpu': '-°C',
'hw-temperature-gpu': '-°C'
}
class OpenHardwareMonitor extends Extension {
constructor(props) {
super(props);
this.setValue = props.setValue;
this.name = 'Hardware Monitor';
this.platforms = [PLATFORMS.WINDOWS];
this.inputs = [
{
label: 'Display CPU Stats',
value: 'hw-cpu',
icon: 'headphones',
mode: 'custom-value',
fontIcon: 'fas',
color: '#8E44AD',
input: [
{
label: 'Select monitor',
type: INPUT_METHOD.INPUT_SELECT,
items: [
{ value: 'hw-load-cpu', label: 'CPU Load' },
{ value: 'hw-temperature-cpu', label: 'CPU Temperature' }
]
}
]
},
{
label: 'Display GPU Stats',
value: 'hw-gpu',
icon: 'headphones',
mode: 'custom-value',
fontIcon: 'fas',
color: '#8E44AD',
input: [
{
label: 'Select monitor',
type: INPUT_METHOD.INPUT_SELECT,
items: [
{ value: 'hw-load-gpu', label: 'GPU Load' },
{ value: 'hw-temperature-gpu', label: 'GPU Temperature' }
]
}
]
}
];
this.configs = [];
}
// Executes when the extensions loaded every time the app start.
initExtension() {
if (process.platform === 'win32')
setInterval(() => {
Query()
.namespace('root/OpenHardwareMonitor')
.class('Sensor')
.where("SensorType='Load' OR SensorType='Temperature'")
.exec((err, data) => {
if (err || !data)
this.setValue(DEFAULT_VALUE)
else this.setValue(data
.filter(({ Name, SensorType }) => CATEGORIZATION[SensorType.toLowerCase()][Name] !== undefined)
.map(({ Name, Value, SensorType }) => ({
key: 'hw-' + SensorType.toLowerCase() + '-' + CATEGORIZATION[SensorType.toLowerCase()][Name],
value: Math.round(Value) + SUFFIX[SensorType.toLowerCase()]
}))
.reduce((data, { key, value }) => ({ ...data, [key]: value }), DEFAULT_VALUE)
)
})
}, 2000)
else this.setValue(DEFAULT_VALUE)
}
execute(action, args) {
return;
};
}
module.exports = (sendData) => new OpenHardwareMonitor(sendData);