@@ -14,6 +14,11 @@ class RAMwatcher {
14
14
}
15
15
16
16
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>
17
22
</div>` ;
18
23
19
24
modExtContainer . innerHTML = ramwatcherDOM ;
@@ -31,41 +36,40 @@ class RAMwatcher {
31
36
}
32
37
updateInfo ( ) {
33
38
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" ) ;
43
40
44
41
// 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 ) ;
47
44
48
45
// Update grid
49
46
this . points . slice ( 0 , active ) . forEach ( domPoint => {
50
47
if ( domPoint . attributes . class . value !== "mod_ramwatcher_point active" ) {
51
48
domPoint . setAttribute ( "class" , "mod_ramwatcher_point active" ) ;
52
49
}
53
50
} ) ;
54
- this . points . slice ( active , available ) . forEach ( domPoint => {
51
+ this . points . slice ( active , active + available ) . forEach ( domPoint => {
55
52
if ( domPoint . attributes . class . value !== "mod_ramwatcher_point available" ) {
56
53
domPoint . setAttribute ( "class" , "mod_ramwatcher_point available" ) ;
57
54
}
58
55
} ) ;
59
- this . points . slice ( available , this . points . length ) . forEach ( domPoint => {
56
+ this . points . slice ( active + available , this . points . length ) . forEach ( domPoint => {
60
57
if ( domPoint . attributes . class . value !== "mod_ramwatcher_point free" ) {
61
58
domPoint . setAttribute ( "class" , "mod_ramwatcher_point free" ) ;
62
59
}
63
60
} ) ;
64
61
65
62
// 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 ;
68
65
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)` ;
69
73
} ) ;
70
74
}
71
75
shuffleArray ( array ) {
0 commit comments