|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <link rel="stylesheet" href="../../css/spectre.min.css"> |
| 4 | + </head> |
| 5 | + <body> |
| 6 | + |
| 7 | + <script src="../../core/lib/customize.js"></script> |
| 8 | + <div id="storageInfo"></div> |
| 9 | + |
| 10 | + <script> |
| 11 | + // Called when we know what device we're using |
| 12 | + function onInit(device) { |
| 13 | + Util.showModal("Reading Storage..."); |
| 14 | + Puck.eval(`require("Storage").list(/\\.info$/).map(appInfoName => { |
| 15 | + let appInfo = require("Storage").readJSON(appInfoName,1)||{}; |
| 16 | + //print(appInfoName, appInfo); |
| 17 | + var fileSize = 0, dataSize = 0; |
| 18 | + appInfo.files.split(",").forEach(f => fileSize += require("Storage").read(f).length); |
| 19 | + var data = (appInfo.data||"").split(";"); |
| 20 | + function wildcardToRegexp(wc) { |
| 21 | + return new RegExp("^"+wc.replaceAll(".","\\\\.").replaceAll("?",".*")+"$"); |
| 22 | + } |
| 23 | + // normal files |
| 24 | + if (data[0]) data[0].split(",").forEach(wc => { |
| 25 | + require("Storage").list(wildcardToRegexp(wc), {sf:false}).forEach(f => { |
| 26 | + dataSize += require("Storage").read(f).length |
| 27 | + }); |
| 28 | + }); |
| 29 | + // storage files |
| 30 | + if (data[1]) data[1].split(",").forEach(wc => { |
| 31 | + require("Storage").list(wildcardToRegexp(wc), {sf:true}).forEach(f => { |
| 32 | + dataSize += require("Storage").open(f,"r").getLength(); |
| 33 | + }); |
| 34 | + }); |
| 35 | + return [appInfo.id, fileSize, dataSize]; |
| 36 | +})`, function(apps) { |
| 37 | + apps.sort((a,b) => (b[1]+b[2]) - (a[1]+a[2])); |
| 38 | + Util.hideModal(); |
| 39 | + console.log(apps); |
| 40 | + document.getElementById("storageInfo").innerHTML = ` |
| 41 | + <table class="table table-striped"> |
| 42 | + <thead> |
| 43 | + <tr> |
| 44 | + <th>App</th> |
| 45 | + <th>Code (kb)</th> |
| 46 | + <th>Data (kb)</th> |
| 47 | + <th>Total (kb)</th> |
| 48 | + </tr> |
| 49 | + </thead> |
| 50 | + <tbody> |
| 51 | + ${apps.map(app => ` |
| 52 | + <tr> |
| 53 | + <td>${app[0]}</td> |
| 54 | + <td>${(app[1]/1000).toFixed(1)}</td> |
| 55 | + <td>${(app[2]/1000).toFixed(1)}</td> |
| 56 | + <td>${((app[1]+app[2])/1000).toFixed(1)}</td> |
| 57 | + </tr>`).join("")} |
| 58 | + </tbody> |
| 59 | + </table>`; |
| 60 | + if (apps.length === 0) { |
| 61 | + document.getElementById("storageInfo").innerHTML = "<p>No apps found</p>"; |
| 62 | + } |
| 63 | +}); |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + </script> |
| 68 | + </body> |
| 69 | +</html> |
0 commit comments