Show total storage pie

master
RKBoss6 2025-07-14 17:20:46 -04:00 committed by GitHub
parent 7ea4f886c0
commit 51e6f374a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 53 additions and 41 deletions

View File

@ -16,17 +16,19 @@
<div id="storageTable"></div> <div id="storageTable"></div>
<!-- Chart View --> <!-- Chart View -->
<div id="storagePieChart" style="display: none; justify-content: center;"> <div id="storagePieChart" style="display: none; flex-direction: column; align-items: center;">
<div id="piechart" style="width: 100%; max-width: 600px; height: 400px;"></div> <div id="piechart" style="width: 100%; max-width: 600px; height: 400px;"></div>
<div id="totalStoragePie" style="width: 100%; max-width: 600px; height: 300px;"></div>
</div> </div>
<script> <script>
let globalApps = []; let globalApps = [];
let storageStats = null;
// Called by the app loader
function onInit(device) { function onInit(device) {
Util.showModal("Reading Storage..."); Util.showModal("Reading Storage...");
Puck.eval(`require("Storage").list(/\\.info$/).map(appInfoName => { Puck.eval(`(()=>{
let getApps = () => require("Storage").list(/\\.info$/).map(appInfoName => {
let appInfo = require("Storage").readJSON(appInfoName,1)||{}; let appInfo = require("Storage").readJSON(appInfoName,1)||{};
var fileSize = 0, dataSize = 0; var fileSize = 0, dataSize = 0;
appInfo.files.split(",").forEach(f => fileSize += require("Storage").read(f).length); appInfo.files.split(",").forEach(f => fileSize += require("Storage").read(f).length);
@ -45,11 +47,13 @@
}); });
}); });
return [appInfo.id, fileSize, dataSize]; return [appInfo.id, fileSize, dataSize];
})`, function(apps) { });
return [getApps(), require(\"Storage\").getStats()]; })()`, function(result) {
Util.hideModal(); Util.hideModal();
globalApps = apps.sort((a,b) => (b[1]+b[2]) - (a[1]+a[2])); globalApps = result[0].sort((a,b) => (b[1]+b[2]) - (a[1]+a[2]));
storageStats = result[1];
if (apps.length === 0) { if (globalApps.length === 0) {
document.getElementById("storageTable").innerHTML = "<p>No apps found</p>"; document.getElementById("storageTable").innerHTML = "<p>No apps found</p>";
return; return;
} }
@ -84,40 +88,51 @@
function drawChart() { function drawChart() {
if (globalApps.length === 0) return; if (globalApps.length === 0) return;
// App-specific chart
const chartData = [ const chartData = [
['App', 'Total Size'] ['App', 'Total Size (KB)']
].concat(globalApps.map(app => [app[0], (app[1] + app[2])/1000])); ].concat(globalApps.map(app => [app[0], (app[1] + app[2])/1000]));
const data = google.visualization.arrayToDataTable(chartData); const data = google.visualization.arrayToDataTable(chartData);
const options = { const options = {
title: 'App Storage Breakdown (in KBs)', title: 'App Storage Breakdown',
is3D: false, chartArea: { width: '90%', height: '80%' },
chartArea: { legend: { position: 'bottom' }
width: '90%',
height: '80%'
},
legend: {
position: 'bottom'
}
}; };
const chart = new google.visualization.PieChart(document.getElementById('piechart')); const chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options); chart.draw(data, options);
// Total storage chart
if (storageStats) {
const usedKB = storageStats.usedBytes / 1000;
const freeKB = storageStats.freeBytes / 1000;
const totalData = google.visualization.arrayToDataTable([
['Type', 'KB'],
['Used', usedKB],
['Free', freeKB]
]);
const totalOptions = {
title: 'Total Storage Usage',
pieHole: 0.4,
chartArea: { width: '90%', height: '80%' },
legend: { position: 'bottom' }
};
const totalChart = new google.visualization.PieChart(document.getElementById('totalStoragePie'));
totalChart.draw(totalData, totalOptions);
}
} }
// Load Google Charts and prepare initial chart (in background)
google.charts.load('current', {'packages':['corechart']}); google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(() => {
drawChart();
});
// Toggle view buttons
document.getElementById("pieChartButton").addEventListener("click", function () { document.getElementById("pieChartButton").addEventListener("click", function () {
document.getElementById("storageTable").style.display = "none"; document.getElementById("storageTable").style.display = "none";
document.getElementById("storagePieChart").style.display = "flex"; document.getElementById("storagePieChart").style.display = "flex";
drawChart(); drawChart();
this.classList.add("btn-primary"); this.classList.add("btn-primary");
document.getElementById("tableButton").classList.remove("btn-primary"); document.getElementById("tableButton").classList.remove("btn-primary");
}); });
@ -126,13 +141,10 @@
document.getElementById("storageTable").style.display = "block"; document.getElementById("storageTable").style.display = "block";
document.getElementById("storagePieChart").style.display = "none"; document.getElementById("storagePieChart").style.display = "none";
drawTable(); drawTable();
this.classList.add("btn-primary"); this.classList.add("btn-primary");
document.getElementById("pieChartButton").classList.remove("btn-primary"); document.getElementById("pieChartButton").classList.remove("btn-primary");
}); });
// Register as app loader's entry point
window.onInit = onInit;
</script> </script>
</body> </body>
</html> </html>