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

Commit a8e29ce

Browse files
feat: more file types available in file editor (#975) #973
Co-authored-by: Gabriel Saillard <[email protected]>
1 parent b19c4bc commit a8e29ce

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"electron": "^10.2.0",
111111
"electron-builder": "^22.10.3",
112112
"electron-rebuild": "^2.3.4",
113+
"mime-types": "^2.1.27",
113114
"node-abi": "2.19.3",
114115
"node-json-minify": "1.0.0",
115116
"terser": "^5.5.1"

src/classes/filesystem.class.js

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -554,53 +554,13 @@ class FilesystemDisplay {
554554
name = block.name;
555555
}
556556

557+
let mime = require("mime-types")
558+
557559
block.path = block.path.replace(/\\/g, "/");
558560

559-
let filetype = name.split(".")[name.split(".").length - 1];
561+
let filetype = mime.lookup(name.split(".")[name.split(".").length - 1]);
560562
switch (filetype) {
561-
case "xml":
562-
case "yaml":
563-
case "java":
564-
case "cs":
565-
case "cpp":
566-
case "h":
567-
case "html":
568-
case "css":
569-
case "js":
570-
case "md":
571-
case "log":
572-
case "bat":
573-
case "sh":
574-
case "gd":
575-
//To anyone else working with this: Feel free to add on to this list. - Surge
576-
case "txt":
577-
case "json":
578-
fs.readFile(block.path, 'utf-8', (err, data) => {
579-
if (err) {
580-
new Modal({
581-
type: "info",
582-
title: "Failed to load file: " + block.path,
583-
html: err
584-
});
585-
console.log(err);
586-
};
587-
window.keyboard.detach();
588-
new Modal(
589-
{
590-
type: "custom",
591-
title: _escapeHtml(name),
592-
html: `<textarea id="fileEdit" rows="40" cols="150" spellcheck="false">${data}</textarea><p id="fedit-status"></p>`,
593-
buttons: [
594-
{label:"Save to Disk",action:`window.writeFile('${block.path}')`}
595-
]
596-
}, () => {
597-
window.keyboard.attach();
598-
window.term[window.currentTerm].term.focus();
599-
}
600-
);
601-
});
602-
break;
603-
case "pdf":
563+
case "application/pdf":
604564
let html = `<div>
605565
<div class="pdf_options">
606566
<button class="zoom_in">
@@ -644,7 +604,33 @@ class FilesystemDisplay {
644604
);
645605
break;
646606
default:
647-
return;
607+
if (mime.charset(filetype) === "UTF-8") {
608+
fs.readFile(block.path, 'utf-8', (err, data) => {
609+
if (err) {
610+
new Modal({
611+
type: "info",
612+
title: "Failed to load file: " + block.path,
613+
html: err
614+
});
615+
console.log(err);
616+
};
617+
window.keyboard.detach();
618+
new Modal(
619+
{
620+
type: "custom",
621+
title: _escapeHtml(name),
622+
html: `<textarea id="fileEdit" rows="40" cols="150" spellcheck="false">${data}</textarea><p id="fedit-status"></p>`,
623+
buttons: [
624+
{label:"Save to Disk",action:`window.writeFile('${block.path}')`}
625+
]
626+
}, () => {
627+
window.keyboard.attach();
628+
window.term[window.currentTerm].term.focus();
629+
}
630+
);
631+
});
632+
break;
633+
}
648634
}
649635
}
650636

@@ -753,4 +739,4 @@ class FilesystemDisplay {
753739

754740
module.exports = {
755741
FilesystemDisplay
756-
};
742+
};

src/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
"geolite2-redist": "^2.0.1",
2929
"howler": "2.2.1",
3030
"maxmind": "4.3.1",
31+
"mime-types": "^2.1.27",
3132
"nanoid": "3.1.20",
3233
"node-pty": "0.9.0",
34+
"pdfjs-dist": "2.6.347",
3335
"pretty-bytes": "5.4.1",
3436
"shell-env": "3.0.0",
3537
"signale": "1.4.0",
@@ -42,8 +44,7 @@
4244
"xterm": "4.9.0",
4345
"xterm-addon-attach": "0.6.0",
4446
"xterm-addon-fit": "0.4.0",
45-
"xterm-addon-ligatures": "0.3.0",
46-
"pdfjs-dist": "2.6.347"
47+
"xterm-addon-ligatures": "0.3.0"
4748
},
4849
"optionalDependencies": {
4950
"osx-temperature-sensor": "1.0.7"

0 commit comments

Comments
 (0)