Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit 8492174

Browse files
committed
✨ mod_ramwatcher refactor: swap, more precise info
* Fixed precision of GiB indicated values * Fixed three-level dot grid display not working as intended, it now show correctly cache, active and free mem slots * Added swap monitoring for all OSs
1 parent 04613ff commit 8492174

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

src/assets/css/mod_ramwatcher.css

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,50 @@ div.mod_ramwatcher_point.available {
7878
div.mod_ramwatcher_point.active {
7979
opacity: 1;
8080
}
81+
82+
div#mod_ramwatcher_swapcontainer {
83+
display: grid;
84+
grid-template-columns: 15% 65% 20%;
85+
padding-left: 0.5vh;
86+
margin-bottom: 0.5vh;
87+
}
88+
89+
div#mod_ramwatcher_swapcontainer h1 {
90+
font-size: 1.3vh;
91+
line-height: 1.5vh;
92+
margin: 0vh;
93+
align-self: center;
94+
}
95+
96+
progress#mod_ramwatcher_swapbar {
97+
width: 100%;
98+
align-self: center;
99+
-webkit-appearance: none;
100+
border-right: .1vh solid rgba(var(--color_r), var(--color_g), var(--color_b), 0.8);
101+
}
102+
103+
progress#mod_ramwatcher_swapbar::-webkit-progress-bar {
104+
background: rgba(var(--color_r), var(--color_g), var(--color_b), 0.4);
105+
height: .3vh;
106+
position: relative;
107+
top: .35vh;
108+
}
109+
110+
progress#mod_ramwatcher_swapbar::-webkit-progress-value {
111+
background: rgb(var(--color_r), var(--color_g), var(--color_b));
112+
height: .6vh;
113+
transition: width .5s cubic-bezier(0.4, 0, 1, 1);
114+
position: relative;
115+
bottom: .15vh;
116+
}
117+
118+
h3#mod_ramwatcher_swaptext {
119+
font-style: normal;
120+
font-size: 1.3vh;
121+
line-height: 1.5vh;
122+
opacity: 0.5;
123+
margin: 0vh;
124+
white-space: nowrap;
125+
align-self: center;
126+
text-align: right;
127+
}

src/classes/ramwatcher.class.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)