@@ -995,6 +995,7 @@ function getInstalledApps(refresh) {
995995 device . id = info . id ;
996996 device . version = info . version ;
997997 device . exptr = info . exptr ;
998+ device . storageStats = info . storageStats ;
998999 device . appsInstalled = info . apps ;
9991000 haveInstalledApps = true ;
10001001 if ( "function" == typeof onFoundDeviceInfo )
@@ -1016,11 +1017,39 @@ function getInstalledApps(refresh) {
10161017 const deviceInfoElem = document . getElementById ( "more-deviceinfo" ) ;
10171018 if ( deviceInfoElem ) {
10181019 deviceInfoElem . style . display = "inherit" ;
1020+ let storageRow = "" ;
1021+ if ( device . storageStats ?. totalBytes ) {
1022+ const stats = device . storageStats ;
1023+ const totalKB = ( stats . totalBytes / 1000 ) . toFixed ( 2 ) ;
1024+ const usedKB = ( stats . fileBytes / 1000 ) . toFixed ( 2 ) ;
1025+ const trashKB = ( stats . trashBytes / 1000 ) . toFixed ( 2 ) ;
1026+ const freeKB = ( stats . freeBytes / 1000 ) . toFixed ( 2 ) ;
1027+ const bytePrc = 100 / stats . totalBytes ;
1028+ const usedPrc = bytePrc * stats . fileBytes ;
1029+ const trashPrc = bytePrc * stats . trashBytes ;
1030+ const freePrc = bytePrc * stats . freeBytes ;
1031+ if ( isNaN ( usedPrc ) || isNaN ( trashPrc ) || isNaN ( freePrc ) ) {
1032+ console . error ( "Unexpected error: Could not calculate storage statistics" ) ;
1033+ } else {
1034+ storageRow = `
1035+ <tr><td><b>Storage</b></td><td>
1036+ <p style="margin-bottom:.4rem;">${ totalKB } KiB in total, ${ stats . fileCount } files used, ${ stats . trashCount } files trashed.</p>
1037+ <div class="bar" style="margin-bottom:.3rem;">
1038+ <!-- These styles prevent overflow of text if the bar item is too small to fit all the text -->
1039+ <style>.bar-item{white-space:nowrap;padding-left:.1rem;padding-right:.1rem;}</style>
1040+ <div class="bar-item tooltip bg-error" data-tooltip="${ usedKB } KiB, ${ usedPrc . toFixed ( 2 ) } % used" style="width:${ usedPrc } %; color:hsl(218 16% 2%)">${ usedPrc . toFixed ( 0 ) } % used</div>
1041+ <div class="bar-item tooltip bg-warning" data-tooltip="${ trashKB } KiB, ${ trashPrc . toFixed ( 2 ) } % trash" style="width:${ trashPrc } %;color:hsl(218 16% 7%)">${ trashPrc . toFixed ( 0 ) } % trash</div>
1042+ <div class="bar-item tooltip bg-success" data-tooltip="${ freeKB } KiB, ${ freePrc . toFixed ( 2 ) } % free" style="width:${ freePrc } %; color:hsl(218 16% 7%)">${ freePrc . toFixed ( 0 ) } % free</div>
1043+ </div>
1044+ </td></tr>` ;
1045+ }
1046+ }
10191047 const deviceInfoContentElem = document . getElementById ( "more-deviceinfo-content" ) ;
10201048 deviceInfoContentElem . innerHTML = `
10211049<table class="table"><tbody>
10221050 <tr><td><b>Device Type</b></td><td>${ device . id } </td></tr>
10231051 <tr><td><b>Firmware Version</b></td><td>${ device . version } </td></tr>
1052+ ${ storageRow }
10241053 <tr><td><b>Apps Installed</b></td><td>${ ( device . appsInstalled || [ ] ) . map ( a => `${ a . id } (${ a . version } )` ) . join ( ", " ) } </td></tr>
10251054</tbody></table>` ;
10261055 }
0 commit comments