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

Commit

Permalink
feat: more file types available in file editor (#975) #973
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Saillard <[email protected]>
  • Loading branch information
Animus-Surge and GitSquared committed Dec 22, 2020
1 parent b19c4bc commit a8e29ce
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"electron": "^10.2.0",
"electron-builder": "^22.10.3",
"electron-rebuild": "^2.3.4",
"mime-types": "^2.1.27",
"node-abi": "2.19.3",
"node-json-minify": "1.0.0",
"terser": "^5.5.1"
Expand Down
78 changes: 32 additions & 46 deletions src/classes/filesystem.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,53 +554,13 @@ class FilesystemDisplay {
name = block.name;
}

let mime = require("mime-types")

block.path = block.path.replace(/\\/g, "/");

let filetype = name.split(".")[name.split(".").length - 1];
let filetype = mime.lookup(name.split(".")[name.split(".").length - 1]);
switch (filetype) {
case "xml":
case "yaml":
case "java":
case "cs":
case "cpp":
case "h":
case "html":
case "css":
case "js":
case "md":
case "log":
case "bat":
case "sh":
case "gd":
//To anyone else working with this: Feel free to add on to this list. - Surge
case "txt":
case "json":
fs.readFile(block.path, 'utf-8', (err, data) => {
if (err) {
new Modal({
type: "info",
title: "Failed to load file: " + block.path,
html: err
});
console.log(err);
};
window.keyboard.detach();
new Modal(
{
type: "custom",
title: _escapeHtml(name),
html: `<textarea id="fileEdit" rows="40" cols="150" spellcheck="false">${data}</textarea><p id="fedit-status"></p>`,
buttons: [
{label:"Save to Disk",action:`window.writeFile('${block.path}')`}
]
}, () => {
window.keyboard.attach();
window.term[window.currentTerm].term.focus();
}
);
});
break;
case "pdf":
case "application/pdf":
let html = `<div>
<div class="pdf_options">
<button class="zoom_in">
Expand Down Expand Up @@ -644,7 +604,33 @@ class FilesystemDisplay {
);
break;
default:
return;
if (mime.charset(filetype) === "UTF-8") {
fs.readFile(block.path, 'utf-8', (err, data) => {
if (err) {
new Modal({
type: "info",
title: "Failed to load file: " + block.path,
html: err
});
console.log(err);
};
window.keyboard.detach();
new Modal(
{
type: "custom",
title: _escapeHtml(name),
html: `<textarea id="fileEdit" rows="40" cols="150" spellcheck="false">${data}</textarea><p id="fedit-status"></p>`,
buttons: [
{label:"Save to Disk",action:`window.writeFile('${block.path}')`}
]
}, () => {
window.keyboard.attach();
window.term[window.currentTerm].term.focus();
}
);
});
break;
}
}
}

Expand Down Expand Up @@ -753,4 +739,4 @@ class FilesystemDisplay {

module.exports = {
FilesystemDisplay
};
};
13 changes: 13 additions & 0 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
"geolite2-redist": "^2.0.1",
"howler": "2.2.1",
"maxmind": "4.3.1",
"mime-types": "^2.1.27",
"nanoid": "3.1.20",
"node-pty": "0.9.0",
"pdfjs-dist": "2.6.347",
"pretty-bytes": "5.4.1",
"shell-env": "3.0.0",
"signale": "1.4.0",
Expand All @@ -42,8 +44,7 @@
"xterm": "4.9.0",
"xterm-addon-attach": "0.6.0",
"xterm-addon-fit": "0.4.0",
"xterm-addon-ligatures": "0.3.0",
"pdfjs-dist": "2.6.347"
"xterm-addon-ligatures": "0.3.0"
},
"optionalDependencies": {
"osx-temperature-sensor": "1.0.7"
Expand Down

0 comments on commit a8e29ce

Please sign in to comment.