@@ -995,6 +995,7 @@ function getInstalledApps(refresh) {
995
995
device . id = info . id ;
996
996
device . version = info . version ;
997
997
device . exptr = info . exptr ;
998
+ device . storageStats = info . storageStats ;
998
999
device . appsInstalled = info . apps ;
999
1000
haveInstalledApps = true ;
1000
1001
if ( "function" == typeof onFoundDeviceInfo )
@@ -1016,11 +1017,39 @@ function getInstalledApps(refresh) {
1016
1017
const deviceInfoElem = document . getElementById ( "more-deviceinfo" ) ;
1017
1018
if ( deviceInfoElem ) {
1018
1019
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
+ }
1019
1047
const deviceInfoContentElem = document . getElementById ( "more-deviceinfo-content" ) ;
1020
1048
deviceInfoContentElem . innerHTML = `
1021
1049
<table class="table"><tbody>
1022
1050
<tr><td><b>Device Type</b></td><td>${ device . id } </td></tr>
1023
1051
<tr><td><b>Firmware Version</b></td><td>${ device . version } </td></tr>
1052
+ ${ storageRow }
1024
1053
<tr><td><b>Apps Installed</b></td><td>${ ( device . appsInstalled || [ ] ) . map ( a => `${ a . id } (${ a . version } )` ) . join ( ", " ) } </td></tr>
1025
1054
</tbody></table>` ;
1026
1055
}
0 commit comments