@@ -14,6 +14,11 @@ class RAMwatcher {
1414 }
1515
1616 ramwatcherDOM += `</div>
17+ <div id="mod_ramwatcher_swapcontainer">
18+ <h1>SWAP</h1>
19+ <progress id="mod_ramwatcher_swapbar" max="100" value="0"></progress>
20+ <h3 id="mod_ramwatcher_swaptext">(0.0 GiB)</h3>
21+ </div>
1722 </div>` ;
1823
1924 modExtContainer . innerHTML = ramwatcherDOM ;
@@ -31,41 +36,40 @@ class RAMwatcher {
3136 }
3237 updateInfo ( ) {
3338 window . si . mem ( ) . then ( data => {
34- let total = data . free + data . used ;
35- let free = data . free ;
36- let available = data . used - data . active ;
37- let active = data . active ;
38-
39- if ( process . platform === "win32" ) available = data . available ;
40-
41- if ( free + available + active !== total && process . platform !== "win32" ) throw ( "RAM Watcher Error: Bad memory values" ) ;
42- if ( free + data . used !== total && process . platform === "win32" ) console . warn ( "RAM Watcher Error: Bad memory values" ) ;
39+ if ( data . free + data . used !== data . total ) throw ( "RAM Watcher Error: Bad memory values" ) ;
4340
4441 // Convert the data for the 440-points grid
45- active = Math . round ( ( 440 * active ) / total ) ;
46- available = Math . round ( ( 440 * available ) / total ) ;
42+ let active = Math . round ( ( 440 * data . active ) / data . total ) ;
43+ let available = Math . round ( ( 440 * ( data . available - data . free ) ) / data . total ) ;
4744
4845 // Update grid
4946 this . points . slice ( 0 , active ) . forEach ( domPoint => {
5047 if ( domPoint . attributes . class . value !== "mod_ramwatcher_point active" ) {
5148 domPoint . setAttribute ( "class" , "mod_ramwatcher_point active" ) ;
5249 }
5350 } ) ;
54- this . points . slice ( active , available ) . forEach ( domPoint => {
51+ this . points . slice ( active , active + available ) . forEach ( domPoint => {
5552 if ( domPoint . attributes . class . value !== "mod_ramwatcher_point available" ) {
5653 domPoint . setAttribute ( "class" , "mod_ramwatcher_point available" ) ;
5754 }
5855 } ) ;
59- this . points . slice ( available , this . points . length ) . forEach ( domPoint => {
56+ this . points . slice ( active + available , this . points . length ) . forEach ( domPoint => {
6057 if ( domPoint . attributes . class . value !== "mod_ramwatcher_point free" ) {
6158 domPoint . setAttribute ( "class" , "mod_ramwatcher_point free" ) ;
6259 }
6360 } ) ;
6461
6562 // Update info text
66- let totalGiB = Math . round ( ( total / 1073742000 ) * 2 ) / 2 ; // 1073742000 bytes = 1 Gibibyte (GiB)
67- let usedGiB = Math . round ( ( data . active / 1073742000 ) * 2 ) / 2 ;
63+ let totalGiB = Math . round ( ( data . total / 1073742000 ) * 10 ) / 10 ; // 1073742000 bytes = 1 Gibibyte (GiB), the *10 is to round to .1 decimal
64+ let usedGiB = Math . round ( ( data . active / 1073742000 ) * 10 ) / 10 ;
6865 document . getElementById ( "mod_ramwatcher_info" ) . innerText = `USING ${ usedGiB } OUT OF ${ totalGiB } GiB` ;
66+
67+ // Update swap indicator
68+ let usedSwap = Math . round ( ( 100 * data . swapused ) / data . swaptotal ) ;
69+ document . getElementById ( "mod_ramwatcher_swapbar" ) . value = usedSwap ;
70+
71+ let usedSwapGiB = Math . round ( ( data . swapused / 1073742000 ) * 10 ) / 10 ;
72+ document . getElementById ( "mod_ramwatcher_swaptext" ) . innerText = `(${ usedSwapGiB } GiB)` ;
6973 } ) ;
7074 }
7175 shuffleArray ( array ) {
0 commit comments