Skip to content

Commit 0a962ba

Browse files
authored
Improve memory unit selection for devices with less than 1 GB of RAM (#3270)
2 parents 86210b2 + 9a40f4a commit 0a962ba

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

scripts/js/footer.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,20 @@ function updateSystemInfo() {
330330
var system = data.system;
331331
var percentRAM = system.memory.ram["%used"];
332332
var percentSwap = system.memory.swap["%used"];
333-
var totalRAMGB = system.memory.ram.total / 1024 / 1024;
334-
var totalSwapGB = system.memory.swap.total / 1024 / 1024;
333+
let totalRAM = system.memory.ram.total / 1024;
334+
let totalRAMUnit = "MB";
335+
if (totalRAM > 1024) {
336+
totalRAM /= 1024;
337+
totalRAMUnit = "GB";
338+
}
339+
340+
let totalSwap = system.memory.swap.total / 1024;
341+
let totalSwapUnit = "MB";
342+
if (totalSwap > 1024) {
343+
totalSwap /= 1024;
344+
totalSwapUnit = "GB";
345+
}
346+
335347
var swap =
336348
system.memory.swap.total > 0
337349
? ((1e2 * system.memory.swap.used) / system.memory.swap.total).toFixed(1) + " %"
@@ -347,14 +359,14 @@ function updateSystemInfo() {
347359
);
348360
$("#memory").prop(
349361
"title",
350-
"Total memory: " + totalRAMGB.toFixed(1) + " GB, Swap usage: " + swap
362+
"Total memory: " + totalRAM.toFixed(1) + " " + totalRAMUnit + ", Swap usage: " + swap
351363
);
352364
$("#sysinfo-memory-ram").text(
353-
percentRAM.toFixed(1) + "% of " + totalRAMGB.toFixed(1) + " GB is used"
365+
percentRAM.toFixed(1) + "% of " + totalRAM.toFixed(1) + " " + totalRAMUnit + " is used"
354366
);
355367
if (system.memory.swap.total > 0) {
356368
$("#sysinfo-memory-swap").text(
357-
percentSwap.toFixed(1) + "% of " + totalSwapGB.toFixed(1) + " GB is used"
369+
percentSwap.toFixed(1) + "% of " + totalSwap.toFixed(1) + " " + totalSwapUnit + " is used"
358370
);
359371
} else {
360372
$("#sysinfo-memory-swap").text("No swap space available");

0 commit comments

Comments
 (0)