Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where Ram button is bugged #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions extension.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Open Hardware Monitor
package: open-hardware-monitor
version: 1.0.0
description: Display hardware status from Open Hardware Monitor on Deckboard button
author: Riva Farabi
license: MIT
repository: "https://github.com/rivafarabi/deckboard-ohm"
name: Open Hardware Monitor
package: open-hardware-monitor
version: 1.0.1
description: Display hardware status from Open Hardware Monitor on Deckboard button
author: Riva Farabi
license: MIT
repository: "https://github.com/rivafarabi/deckboard-ohm"
220 changes: 114 additions & 106 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,114 @@
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);
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' }
]
}
]
},
{
label: 'Display RAM Stats',
value: 'hw-load-ram',
icon: 'headphones',
mode: 'custom-value',
fontIcon: 'fas',
color: '#8E44AD'
}
];
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);