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

Commit 590aa0e

Browse files
committed
⚡ Improve visual feedback on slow disks
1 parent a6bac76 commit 590aa0e

File tree

2 files changed

+59
-26
lines changed

2 files changed

+59
-26
lines changed

src/assets/css/filesystem.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ div#fs_space_bar > progress::after {
186186
background: rgba(var(--color_r), var(--color_g), var(--color_b), 0.8);
187187
}
188188

189+
div#fs_space_bar > progress:not([value])::after {
190+
animation: space_bar_working 1.7s ease-in-out alternate infinite;
191+
background: rgba(var(--color_r), var(--color_g), var(--color_b), 1);
192+
}
193+
194+
@keyframes space_bar_working {
195+
0% { right: 0%; }
196+
100% { right: 70%; }
197+
}
198+
189199
div#fs_space_bar > progress::-webkit-progress-bar {
190200
background: rgba(var(--color_r), var(--color_g), var(--color_b), 0.4);
191201
height: .7vh;

src/classes/filesystem.class.js

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ class FilesystemDisplay {
135135
this.readFS = async dir => {
136136
if (this.failed === true || this._reading) return false;
137137
this._reading = true;
138+
139+
document.getElementById("fs_disp_title_dir").innerText = this.dirpath;
140+
this.filesContainer.setAttribute("class", "");
141+
this.filesContainer.innerHTML = "";
142+
if (this._noTracking) {
143+
document.querySelector("section#filesystem > h3.title > p:first-of-type").innerText = "FILESYSTEM - TRACKING FAILED, RUNNING DETACHED FROM TTY";
144+
}
145+
138146
if (process.platform === "win32" && dir.endsWith(":")) dir = dir+"\\";
139147
let tcwd = dir;
140148
let content = await this._asyncFSwrapper.readdir(tcwd).catch(err => {
@@ -149,6 +157,8 @@ class FilesystemDisplay {
149157
}
150158
});
151159

160+
this.reCalculateDiskUsage(tcwd);
161+
152162
this.cwd = [];
153163

154164
await new Promise((resolve, reject) => {
@@ -226,15 +236,6 @@ class FilesystemDisplay {
226236
});
227237
}
228238

229-
let d = await window.si.fsSize().catch(() => {
230-
this.setFailedState();
231-
});
232-
d.forEach(fsBlock => {
233-
if (tcwd.startsWith(fsBlock.mount)) {
234-
this.fsBlock = fsBlock;
235-
}
236-
});
237-
238239
this.dirpath = tcwd;
239240
this.render(this.cwd);
240241
this._reading = false;
@@ -386,23 +387,6 @@ class FilesystemDisplay {
386387
document.getElementById("fs_space_bar").setAttribute("onclick", "window.fsDisp.render(window.fsDisp.cwd)");
387388
} else {
388389
document.getElementById("fs_space_bar").setAttribute("onclick", "");
389-
390-
let splitter = (process.platform === "win32") ? "\\" : "/";
391-
let displayMount = (this.fsBlock.mount.length < 18) ? this.fsBlock.mount : "..."+splitter+this.fsBlock.mount.split(splitter).pop();
392-
393-
// See #226
394-
if (!isNaN(this.fsBlock.use)) {
395-
this.space_bar.text.innerHTML = `Mount <strong>${displayMount}</strong> used <strong>${Math.round(this.fsBlock.use)}%</strong>`;
396-
this.space_bar.bar.value = Math.round(this.fsBlock.use);
397-
} else if (!isNaN((this.fsBlock.size / this.fsBlock.used) * 100)) {
398-
let usage = Math.round((this.fsBlock.size / this.fsBlock.used) * 100);
399-
400-
this.space_bar.text.innerHTML = `Mount <strong>${displayMount}</strong> used <strong>${usage}%</strong>`;
401-
this.space_bar.bar.value = usage;
402-
} else {
403-
this.space_bar.text.innerHTML = "Could not calculate mountpoint usage.";
404-
this.space_bar.bar.value = 100;
405-
}
406390
}
407391

408392
// Render animation
@@ -420,6 +404,45 @@ class FilesystemDisplay {
420404
}
421405
};
422406

407+
this.reCalculateDiskUsage = async path => {
408+
this.fsBlock = null;
409+
this.space_bar.text.innerHTML = "Calculating available space...";
410+
this.space_bar.bar.removeAttribute("value");
411+
412+
window.si.fsSize().catch(() => {
413+
this.space_bar.text.innerHTML = "Could not calculate mountpoint usage.";
414+
this.space_bar.bar.value = 100;
415+
}).then(d => {
416+
d.forEach(fsBlock => {
417+
if (path.startsWith(fsBlock.mount)) {
418+
this.fsBlock = fsBlock;
419+
}
420+
});
421+
this.renderDiskUsage(this.fsBlock);
422+
});
423+
};
424+
425+
this.renderDiskUsage = async fsBlock => {
426+
if (document.getElementById("fs_space_bar").getAttribute("onclick") !== "" || fsBlock === null) return;
427+
428+
let splitter = (process.platform === "win32") ? "\\" : "/";
429+
let displayMount = (fsBlock.mount.length < 18) ? fsBlock.mount : "..."+splitter+fsBlock.mount.split(splitter).pop();
430+
431+
// See #226
432+
if (!isNaN(fsBlock.use)) {
433+
this.space_bar.text.innerHTML = `Mount <strong>${displayMount}</strong> used <strong>${Math.round(fsBlock.use)}%</strong>`;
434+
this.space_bar.bar.value = Math.round(fsBlock.use);
435+
} else if (!isNaN((fsBlock.size / fsBlock.used) * 100)) {
436+
let usage = Math.round((fsBlock.size / fsBlock.used) * 100);
437+
438+
this.space_bar.text.innerHTML = `Mount <strong>${displayMount}</strong> used <strong>${usage}%</strong>`;
439+
this.space_bar.bar.value = usage;
440+
} else {
441+
this.space_bar.text.innerHTML = "Could not calculate mountpoint usage.";
442+
this.space_bar.bar.value = 100;
443+
}
444+
};
445+
423446
// Automatically start indexing supposed beginning CWD
424447
// See #365
425448
// ...except if we're hot-reloading, in which case this can mess up the rendering

0 commit comments

Comments
 (0)