Start work on plugin support

This commit is contained in:
The Ghost of FOSS' Future 2024-09-17 18:31:55 -05:00 committed by GitHub
parent 85edf30d93
commit 1d64430cc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -192,6 +192,23 @@
d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z" d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"
/> />
</svg> </svg>
<svg
class="sidebar-icon"
viewBox="0 0 24 24"
fill="#fff"
id="open-plugin-icon"
>
<path d="M15 10H9v5h6v-5zM21 4h-4V2H7v2H3c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM7 4h10v2H7V4zm12 16H5V8h14v12z" />
</svg>
<svg
class="sidebar-icon"
viewBox="0 0 24 24"
fill="#fff"
id="open-folder-plugins-icon"
>
<path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z" />
</svg>
</div> </div>
<div class="main-content"> <div class="main-content">
<div class="file-explorer"> <div class="file-explorer">
@ -409,6 +426,66 @@
} }
}); });
document
.getElementById("open-plugin-icon")
.addEventListener("click", () => {
const input = document.createElement("input");
input.type = "file";
input.accept = ".js";
input.onchange = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = (event) => {
try {
// Load and execute JavaScript code from the file
new Function(event.target.result)();
alert(`Plugin "${file.name}" executed successfully.`);
} catch (err) {
alert(`Failed to execute plugin "${file.name}": ${err.message}`);
}
};
reader.readAsText(file);
};
input.click();
});
document
.getElementById("open-folder-plugins-icon")
.addEventListener("click", () => {
const input = document.createElement("input");
input.type = "file";
input.webkitdirectory = true;
input.onchange = (e) => {
const folderFiles = e.target.files;
let allFilesLoaded = true;
for (let i = 0; i < folderFiles.length; i++) {
const file = folderFiles[i];
if (file.name.endsWith(".js")) {
const reader = new FileReader();
reader.onload = (event) => {
try {
// Load and execute JavaScript code from the file
new Function(event.target.result)();
console.log(`Plugin "${file.name}" executed successfully.`);
} catch (err) {
console.error(`Failed to execute plugin "${file.name}": ${err.message}`);
allFilesLoaded = false;
}
};
reader.readAsText(file);
}
}
if (allFilesLoaded) {
alert("All plugins executed successfully.");
} else {
alert("Some plugins failed to execute. Check console for details.");
}
};
input.click();
});
editor.on("change", () => { editor.on("change", () => {
files[currentFile] = editor.getValue(); files[currentFile] = editor.getValue();
}); });