Switch to SwayFX
This commit is contained in:
parent
6571feaff7
commit
c310042564
41 changed files with 1450 additions and 294 deletions
|
@ -0,0 +1,40 @@
|
|||
class CPUService extends Service {
|
||||
static {
|
||||
Service.register(this, {}, { "current-usage": ["float", "r"] });
|
||||
}
|
||||
|
||||
#previousIdle = 0.0;
|
||||
#previousTotal = 0.0;
|
||||
#currentUsage = 0.0;
|
||||
|
||||
get current_usage() {
|
||||
return this.#currentUsage;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.#update();
|
||||
const interval = setInterval(() => {
|
||||
this.#update();
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
#update() {
|
||||
const currentValues = Utils.exec(
|
||||
"sh -c 'cat /proc/stat | grep cpu | head -n 1 | tr -s \" \"'",
|
||||
)
|
||||
.split(" ")
|
||||
.slice(1, 10)
|
||||
.map(Number);
|
||||
let idle = currentValues[3];
|
||||
let total = currentValues.reduce((a, b) => a + b, 0);
|
||||
this.#currentUsage =
|
||||
1.0 - (idle - this.#previousIdle) / (total - this.#previousTotal);
|
||||
this.#previousIdle = idle;
|
||||
this.#previousTotal = total;
|
||||
this.changed("current-usage");
|
||||
}
|
||||
}
|
||||
|
||||
const cpu = new CPUService();
|
||||
export default cpu;
|
|
@ -0,0 +1,56 @@
|
|||
class RAMService extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
"current-usage": ["float", "r"],
|
||||
"current-usage-percentage": ["float", "r"],
|
||||
"total-available": ["float", "r"],
|
||||
},
|
||||
);
|
||||
}
|
||||
#currentUsage = 0;
|
||||
#totalAvailable = 0;
|
||||
|
||||
get current_usage() {
|
||||
return this.#currentUsage;
|
||||
}
|
||||
|
||||
get current_usage_percentage() {
|
||||
return this.#currentUsage / this.#totalAvailable;
|
||||
}
|
||||
|
||||
get total_available() {
|
||||
return this.#totalAvailable;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.#totalAvailable = Number(
|
||||
Utils.exec(
|
||||
'sh -c \'cat /proc/meminfo | grep MemTotal | tr -s " " | cut -d " " -f 2\'',
|
||||
),
|
||||
);
|
||||
this.#update();
|
||||
const interval = setInterval(() => {
|
||||
this.#update();
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
#update() {
|
||||
this.#currentUsage =
|
||||
this.#totalAvailable -
|
||||
Number(
|
||||
Utils.exec(
|
||||
'sh -c \'cat /proc/meminfo | grep MemAvailable | tr -s " " | cut -d " " -f 2\'',
|
||||
),
|
||||
);
|
||||
this.emit("changed");
|
||||
this.notify("current-usage");
|
||||
this.notify("current-usage-percentage");
|
||||
}
|
||||
}
|
||||
|
||||
const ram = new RAMService();
|
||||
export default ram;
|
Loading…
Add table
Add a link
Reference in a new issue