Use wait_async for get_swap_values

This commit is contained in:
rcassani 2022-06-11 16:12:46 -04:00
parent ff0b99aff6
commit 8bca29b783

View File

@ -103,6 +103,9 @@ SystemMonitorGraph.prototype = {
this.gpu_use = 0; this.gpu_use = 0;
this.gpu_mem = new Array(2).fill(0.0); this.gpu_mem = new Array(2).fill(0.0);
this.ram_values = new Array(2).fill(0.0); this.ram_values = new Array(2).fill(0.0);
this.swap_values = new Array(2).fill(0.0);
// set colors // set colors
switch (this.type) { switch (this.type) {
case "cpu": case "cpu":
@ -170,13 +173,13 @@ SystemMonitorGraph.prototype = {
break; break;
case "swap": case "swap":
let swap_values = this.get_swap_values(); this.get_swap_values();
let swap_use = 100 * swap_values[1] / swap_values[0]; let swap_use = 100 * this.swap_values[1] / this.swap_values[0];
value = swap_use / 100; value = swap_use / 100;
text1 = _("Swap"); text1 = _("Swap");
text2 = Math.round(swap_use).toString() + "%" text2 = Math.round(swap_use).toString() + "%"
text3 = swap_values[1].toFixed(1) + " / " text3 = this.swap_values[1].toFixed(1) + " / "
+ swap_values[0].toFixed(1) + " " + _("GiB"); + this.swap_values[0].toFixed(1) + " " + _("GiB");
break; break;
case "hdd": case "hdd":
@ -368,13 +371,19 @@ SystemMonitorGraph.prototype = {
get_swap_values: function() { get_swap_values: function() {
// used = total - available // used = total - available
let mem_out = Cinnamon.get_file_contents_utf8_sync("/proc/meminfo"); let subprocess = new Gio.Subprocess({
let mem_tot = parseInt(mem_out.match(/(SwapTotal):\D+(\d+)/)[2]); argv: ['cat', '/proc/meminfo'],
let mem_usd = mem_tot - parseInt(mem_out.match(/(SwapFree):\D+(\d+)/)[2]); flags: Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE,
});
let swap_tot = mem_tot / GIB_TO_KIB; subprocess.init(null);
let swap_usd = mem_usd / GIB_TO_KIB; subprocess.wait_async(null, (sourceObject, res) => {
return [swap_tot, swap_usd]; let [, stdout, stderr] = sourceObject.communicate_utf8(null, null);
let mem_tot = parseInt(stdout.match(/(SwapTotal):\D+(\d+)/)[2]);
let mem_usd = mem_tot - parseInt(stdout.match(/(SwapFree):\D+(\d+)/)[2]);
let swap_tot = mem_tot / GIB_TO_KIB;
let swap_usd = mem_usd / GIB_TO_KIB;
this.swap_values = [swap_tot, swap_usd];
});
}, },
get_hdd_values: function(dir_path) { get_hdd_values: function(dir_path) {