mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-05 01:10:24 +00:00
Base: Use the correct memory unit suffixes in about::processes
Previously the GB suffix was displayed as BB.
This commit is contained in:
Notes:
github-actions[bot]
2025-12-01 12:31:27 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/e9519b132ff Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6734 Reviewed-by: https://github.com/trflynn89 ✅
@@ -76,18 +76,16 @@
|
||||
</thead>
|
||||
<tbody id="process-table"></tbody>
|
||||
</table>
|
||||
|
||||
<script type="text/javascript">
|
||||
const cpuFormatter = new Intl.NumberFormat([], {
|
||||
<script type="module">
|
||||
import { getByteFormatter } from "resource://ladybird/utils.js";
|
||||
const memoryFormatter = getByteFormatter(() => {
|
||||
return {
|
||||
unitDisplay: "narrow",
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
|
||||
const memoryFormatter = new Intl.NumberFormat([], {
|
||||
style: "unit",
|
||||
unit: "byte",
|
||||
notation: "compact",
|
||||
unitDisplay: "narrow",
|
||||
}
|
||||
})
|
||||
const cpuFormatter = new Intl.NumberFormat([], {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
@@ -141,7 +139,7 @@
|
||||
insertColumn(row, process.name);
|
||||
insertColumn(row, process.pid);
|
||||
insertColumn(row, cpuFormatter.format(process.cpu));
|
||||
insertColumn(row, memoryFormatter.format(process.memory));
|
||||
insertColumn(row, memoryFormatter.formatBytes(process.memory));
|
||||
});
|
||||
|
||||
oldTable.parentNode.replaceChild(newTable, oldTable);
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import { getByteFormatter } from "../../utils.js";
|
||||
const byteFormatter = getByteFormatter(unit => {
|
||||
return {
|
||||
unitDisplay: unit === "byte" ? "long" : "short",
|
||||
maximumFractionDigits: 1,
|
||||
};
|
||||
});
|
||||
|
||||
const clearBrowsingData = document.querySelector("#clear-browsing-data");
|
||||
const clearBrowsingDataCachedFiles = document.querySelector("#clear-browsing-data-cached-files");
|
||||
const clearBrowsingDataCachedFilesSize = document.querySelector("#clear-browsing-data-cached-files-size");
|
||||
@@ -10,37 +18,6 @@ const clearBrowsingDataTimeRange = document.querySelector("#clear-browsing-data-
|
||||
const clearBrowsingDataTotalSize = document.querySelector("#clear-browsing-data-total-size");
|
||||
const globalPrivacyControlToggle = document.querySelector("#global-privacy-control-toggle");
|
||||
|
||||
const BYTE_UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
||||
|
||||
const BYTE_FORMATTERS = {
|
||||
byte: undefined,
|
||||
kilobyte: undefined,
|
||||
megabyte: undefined,
|
||||
gigabyte: undefined,
|
||||
terabyte: undefined,
|
||||
};
|
||||
|
||||
function formatBytes(bytes) {
|
||||
let index = 0;
|
||||
while (bytes >= 1024 && index < BYTE_UNITS.length - 1) {
|
||||
bytes /= 1024;
|
||||
++index;
|
||||
}
|
||||
|
||||
const unit = BYTE_UNITS[index];
|
||||
|
||||
if (!BYTE_FORMATTERS[unit]) {
|
||||
BYTE_FORMATTERS[unit] = new Intl.NumberFormat([], {
|
||||
style: "unit",
|
||||
unit: unit,
|
||||
unitDisplay: unit === "byte" ? "long" : "short",
|
||||
maximumFractionDigits: 1,
|
||||
});
|
||||
}
|
||||
|
||||
return BYTE_FORMATTERS[unit].format(bytes);
|
||||
}
|
||||
|
||||
function loadSettings(settings) {
|
||||
globalPrivacyControlToggle.checked = settings.globalPrivacyControl;
|
||||
}
|
||||
@@ -74,10 +51,10 @@ function estimateBrowsingDataSizes() {
|
||||
function updateBrowsingDataSizes(sizes) {
|
||||
const totalSize = sizes.totalCacheSize + sizes.totalSiteDataSize;
|
||||
|
||||
clearBrowsingDataTotalSize.innerText = `Your browsing data is currently using ${formatBytes(totalSize)} of disk space`;
|
||||
clearBrowsingDataTotalSize.innerText = `Your browsing data is currently using ${byteFormatter.formatBytes(totalSize)} of disk space`;
|
||||
|
||||
clearBrowsingDataCachedFilesSize.innerText = ` (remove ${formatBytes(sizes.cacheSizeSinceRequestedTime)})`;
|
||||
clearBrowsingDataSiteDataSize.innerText = ` (remove ${formatBytes(sizes.siteDataSizeSinceRequestedTime)})`;
|
||||
clearBrowsingDataCachedFilesSize.innerText = ` (remove ${byteFormatter.formatBytes(sizes.cacheSizeSinceRequestedTime)})`;
|
||||
clearBrowsingDataSiteDataSize.innerText = ` (remove ${byteFormatter.formatBytes(sizes.siteDataSizeSinceRequestedTime)})`;
|
||||
}
|
||||
|
||||
clearBrowsingData.addEventListener("click", () => {
|
||||
|
||||
32
Base/res/ladybird/utils.js
Normal file
32
Base/res/ladybird/utils.js
Normal file
@@ -0,0 +1,32 @@
|
||||
export function getByteFormatter(optionsFunction) {
|
||||
const BYTE_UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
||||
const BYTE_FORMATTERS = {
|
||||
byte: undefined,
|
||||
kilobyte: undefined,
|
||||
megabyte: undefined,
|
||||
gigabyte: undefined,
|
||||
terabyte: undefined,
|
||||
petabyte: undefined,
|
||||
};
|
||||
return {
|
||||
formatBytes: bytes => {
|
||||
let index = 0;
|
||||
while (bytes >= 1024 && index < BYTE_UNITS.length - 1) {
|
||||
bytes /= 1024;
|
||||
++index;
|
||||
}
|
||||
|
||||
const unit = BYTE_UNITS[index];
|
||||
|
||||
if (!BYTE_FORMATTERS[unit]) {
|
||||
let options = { style: "unit", unit: unit };
|
||||
if (optionsFunction) {
|
||||
options = { ...options, ...optionsFunction(unit) };
|
||||
}
|
||||
BYTE_FORMATTERS[unit] = new Intl.NumberFormat([], options);
|
||||
}
|
||||
|
||||
return BYTE_FORMATTERS[unit].format(bytes);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -63,6 +63,7 @@ list(TRANSFORM BROWSER_ICONS PREPEND "${LADYBIRD_SOURCE_DIR}/Base/res/icons/brow
|
||||
|
||||
set(INTERNAL_RESOURCES
|
||||
ladybird.css
|
||||
utils.js
|
||||
)
|
||||
list(TRANSFORM INTERNAL_RESOURCES PREPEND "${LADYBIRD_SOURCE_DIR}/Base/res/ladybird/")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user