SystemMonitor: adjust strings

This commit is contained in:
Ly-sec
2025-12-16 00:31:11 +01:00
parent 81df597990
commit ec807bc01d
2 changed files with 50 additions and 6 deletions
+2 -2
View File
@@ -109,7 +109,7 @@ Rectangle {
font.family: Settings.data.ui.fontFixed
font.weight: Style.fontWeightMedium
font.pointSize: textSize * Settings.data.ui.fontFixedScale
text: "99.9K" // Longest value part of network speed
text: "12.3G" // Representative of formatted memory/network values (smart formatting keeps most values to 5 chars or less)
}
anchors.centerIn: parent
@@ -471,7 +471,7 @@ Rectangle {
}
NText {
text: showMemoryAsPercent ? `${Math.round(SystemStatService.memPercent)}%` : `${SystemStatService.memGb.toFixed(1)}G`
text: showMemoryAsPercent ? `${Math.round(SystemStatService.memPercent)}%` : SystemStatService.formatMemoryGb(SystemStatService.memGb)
family: Settings.data.ui.fontFixed
pointSize: textSize
applyUiScale: false
+48 -4
View File
@@ -587,14 +587,38 @@ Singleton {
if (bytesPerSecond < 1024 * 1024) {
const kb = bytesPerSecond / 1024;
if (kb < 10) {
return kb.toFixed(1) + "KB";
let formatted = kb.toFixed(1) + "KB";
if (formatted.length > 5) {
formatted = kb.toFixed(1) + "K";
}
return formatted;
} else {
return Math.round(kb) + "KB";
let formatted = Math.round(kb) + "KB";
if (formatted.length > 5) {
formatted = Math.round(kb) + "K";
}
return formatted;
}
} else if (bytesPerSecond < 1024 * 1024 * 1024) {
return (bytesPerSecond / (1024 * 1024)).toFixed(1) + "MB";
const mb = bytesPerSecond / (1024 * 1024);
let formatted = mb.toFixed(1) + "MB";
if (formatted.length > 5) {
formatted = mb.toFixed(1) + "M";
if (formatted.length > 5) {
formatted = Math.round(mb) + "M";
}
}
return formatted;
} else {
return (bytesPerSecond / (1024 * 1024 * 1024)).toFixed(1) + "GB";
const gb = bytesPerSecond / (1024 * 1024 * 1024);
let formatted = gb.toFixed(1) + "GB";
if (formatted.length > 5) {
formatted = gb.toFixed(1) + "G";
if (formatted.length > 5) {
formatted = Math.round(gb) + "G";
}
}
return formatted;
}
}
@@ -619,6 +643,26 @@ Singleton {
return display + units[unitIndex];
}
// -------------------------------------------------------
// Smart formatter for memory values (GB) that prevents elision
// Tries to keep within 5 chars when possible, rounds if needed
function formatMemoryGb(memGb) {
// memGb is already a string from toFixed(1), convert to number
const value = parseFloat(memGb);
if (isNaN(value))
return "0G";
// Try with 1 decimal and "G"
let formatted = value.toFixed(1) + "G";
// If longer than 5 chars (e.g., "123.4G"), round to integer
if (formatted.length > 5) {
formatted = Math.round(value) + "G";
}
return formatted;
}
// -------------------------------------------------------
// Function to start fetching and computing the cpu temperature
function updateCpuTemperature() {