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

Commit 40185f8

Browse files
committed
🏁 Fallback from CWD tracking on Windows
#97
1 parent 059dada commit 40185f8

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

src/classes/filesystem.class.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class FilesystemDisplay {
3636
bar: document.querySelector("#fs_space_bar > progress")
3737
};
3838
this.fsBlock = {};
39+
this.dirpath = "";
3940
this.failed = false;
41+
this._noTracking = false;
4042
this._runNextTick = false;
4143

4244
this._timer = setInterval(() => {
@@ -53,26 +55,30 @@ class FilesystemDisplay {
5355
<h2 id="fs_disp_error">CANNOT ACCESS CURRENT WORKING DIRECTORY</h2>`;
5456
};
5557

56-
window.term.oncwdchange = () => {
57-
if (window.term.cwd) {
58-
this.readFS();
59-
this.watchFS();
58+
window.term.oncwdchange = (cwd) => {
59+
if (cwd) {
60+
if (cwd.startsWith("FALLBACK |-- ")) {
61+
this.readFS(cwd.slice(13));
62+
this._noTracking = true;
63+
} else {
64+
this.readFS(cwd);
65+
this.watchFS(cwd);
66+
}
6067
}
6168
};
6269

63-
this.watchFS = () => {
70+
this.watchFS = (dir) => {
6471
if (this._fsWatcher) {
6572
this._fsWatcher.close();
6673
}
67-
this._fsWatcher = fs.watch(window.term.cwd, () => {
74+
this._fsWatcher = fs.watch(dir, () => {
6875
this._runNextTick = true;
6976
});
7077
};
7178

72-
this.readFS = () => {
79+
this.readFS = (dir) => {
7380
if (this.failed === true) return false;
74-
let tcwd = window.term.cwd;
75-
document.getElementById("fs_disp_title_dir").innerText = tcwd;
81+
let tcwd = dir;
7682
fs.readdir(tcwd, (err, content) => {
7783
if (err !== null) {
7884
this.setFailedState();
@@ -170,6 +176,7 @@ class FilesystemDisplay {
170176
}
171177
});
172178

179+
this.dirpath = tcwd;
173180
this.render();
174181
});
175182
}
@@ -182,6 +189,12 @@ class FilesystemDisplay {
182189

183190
this.render = () => {
184191
if (this.failed === true) return false;
192+
193+
document.getElementById("fs_disp_title_dir").innerText = this.dirpath;
194+
if (this._noTracking) {
195+
document.querySelector("section#filesystem > h3.title > p:first-of-type").innerText = "FILESYSTEM - TRACKING FAILED, RUNNING DETACHED FROM TTY";
196+
}
197+
185198
let filesDOM = ``;
186199
this.cwd.forEach(e => {
187200
let hidden = "";
@@ -193,6 +206,14 @@ class FilesystemDisplay {
193206
if (e.type === "dir" || e.type === "up") {
194207
cmd = `window.term.writelr('cd ${e.name}')`;
195208
}
209+
210+
if (e.type === "up" && this._noTracking) {
211+
cmd = `window.fsDisp.readFS('${path.resolve(this.dirpath, '..')}')`;
212+
}
213+
if (e.type === "dir" && this._noTracking) {
214+
cmd = `window.fsDisp.readFS('${path.resolve(this.dirpath, e.name)}')`;
215+
}
216+
196217
if (e.type === "edex-theme") {
197218
cmd = `window.themeChanger('${e.name.slice(0, -5)}')`;
198219
}

src/classes/terminal.class.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ class Terminal {
7979
switch(args[0]) {
8080
case "New cwd":
8181
this.cwd = args[1];
82-
this.oncwdchange();
82+
this.oncwdchange(this.cwd);
83+
break;
84+
case "Fallback cwd":
85+
this.cwd = "FALLBACK |-- "+args[1];
86+
this.oncwdchange(this.cwd);
8387
break;
8488
default:
8589
return;
@@ -214,7 +218,7 @@ class Terminal {
214218
console.log("Error while tracking TTY working directory: ", e);
215219
this._disableCWDtracking = true;
216220
if (this.renderer) {
217-
this.renderer.send("terminal_channel-"+this.port, "New cwd", opts.cwd || process.env.PWD);
221+
this.renderer.send("terminal_channel-"+this.port, "Fallback cwd", opts.cwd || process.env.PWD);
218222
}
219223
});
220224
}
@@ -247,9 +251,12 @@ class Terminal {
247251
switch(args[0]) {
248252
case "Renderer startup":
249253
this.renderer = e.sender;
250-
if (this._disableCWDtracking === false && this.tty._cwd) {
254+
if (!this._disableCWDtracking && this.tty._cwd) {
251255
this.renderer.send("terminal_channel-"+this.port, "New cwd", this.tty._cwd);
252256
}
257+
if (this._disableCWDtracking) {
258+
this.renderer.send("terminal_channel-"+this.port, "Fallback cwd", opts.cwd || process.env.PWD);
259+
}
253260
break;
254261
case "Resize":
255262
let cols = args[1];

0 commit comments

Comments
 (0)