From 83bd8433f0f51e7ca63a5ca05979eae5515b16b2 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Fri, 9 May 2025 18:29:53 -0700 Subject: [PATCH 1/4] Create Script System --- install.bat | 1 - package-lock.json | 1 + package.json | 1 + scripts/linux/launch.sh | 3 + scripts/linux/postinstall/fix-sandbox.js | 29 +++++++++ scripts/postinstall.js | 63 ++++++++++++++++++++ build.bat => scripts/win32/build.bat | 2 + scripts/win32/install.bat | 4 ++ launch.bat => scripts/win32/launch.bat | 2 + lineCount.bat => scripts/win32/lineCount.bat | 2 + lint.bat => scripts/win32/lint.bat | 2 + pretty.bat => scripts/win32/pretty.bat | 2 + 12 files changed, 111 insertions(+), 1 deletion(-) delete mode 100644 install.bat create mode 100755 scripts/linux/launch.sh create mode 100644 scripts/linux/postinstall/fix-sandbox.js create mode 100644 scripts/postinstall.js rename build.bat => scripts/win32/build.bat (71%) create mode 100644 scripts/win32/install.bat rename launch.bat => scripts/win32/launch.bat (61%) rename lineCount.bat => scripts/win32/lineCount.bat (80%) rename lint.bat => scripts/win32/lint.bat (64%) rename pretty.bat => scripts/win32/pretty.bat (72%) diff --git a/install.bat b/install.bat deleted file mode 100644 index 59a8e22..0000000 --- a/install.bat +++ /dev/null @@ -1 +0,0 @@ -npm i \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cdda013..dcc675e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "webbox", "version": "0.11.0", + "hasInstallScript": true, "license": "ISC", "dependencies": { "highlight.js": "^11.11.1", diff --git a/package.json b/package.json index cf616ed..961a012 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Live Editor for HTML, CSS and JS", "main": "main.js", "scripts": { + "postinstall": "node scripts/postinstall.js", "start": "electron ." }, "author": "Ethan Mahlstedt", diff --git a/scripts/linux/launch.sh b/scripts/linux/launch.sh new file mode 100755 index 0000000..1817204 --- /dev/null +++ b/scripts/linux/launch.sh @@ -0,0 +1,3 @@ +cd .. +cd .. +npm start \ No newline at end of file diff --git a/scripts/linux/postinstall/fix-sandbox.js b/scripts/linux/postinstall/fix-sandbox.js new file mode 100644 index 0000000..b0c46b8 --- /dev/null +++ b/scripts/linux/postinstall/fix-sandbox.js @@ -0,0 +1,29 @@ +// scripts/linux/fix-sandbox.js +const { execSync } = require("child_process"); +const path = require("path"); +const fs = require("fs"); + + +module.exports = function () { + if (process.platform === "linux") { + // Correct path to node_modules/electron/dist/chrome-sandbox + const sandboxPath = path.resolve( + __dirname, + "../../../node_modules/electron/dist/chrome-sandbox" + ); + + console.log("Fixing sandbox permissions... (sudo password may be required)"); + + if (fs.existsSync(sandboxPath)) { + try { + execSync(`sudo chown root ${sandboxPath}`); + execSync(`sudo chmod 4755 ${sandboxPath}`); + console.log("✔ Sandbox permissions fixed."); + } catch (err) { + console.warn("⚠ Failed to fix sandbox permissions:", err.message); + } + } else { + console.warn("⚠ Sandbox file not found at:", sandboxPath); + } + } +} \ No newline at end of file diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 0000000..1b9f71e --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,63 @@ +const fs = require("fs"); +const path = require("path"); +const os = require("os"); + +const { execSync } = require("child_process"); + +const platform = os.platform(); +const arch = os.arch(); + +switch (platform) { + case "darwin": + // macOS specific code + switch (arch) { + case "x64": { + const scripts = fs.readdirSync(path.join(__dirname, "darwin-x64", "postinstall")); + scripts.forEach((script) => { + if(script.endsWith(".js")) { + require(path.join(__dirname, "darwin-x64", "postinstall", script))(); + } + }) + break; + } + case "arm64": { + const scripts = fs.readdirSync(path.join(__dirname, "darwin-arm64", "postinstall")); + scripts.forEach((script) => { + if(script.endsWith(".js")) { + require(path.join(__dirname, "darwin-arm64", "postinstall", script))(); + } + }) + break; + } + default: + console.log("Are you still using PowerPC?"); + } + break; + case "linux": { + const scripts = fs.readdirSync(path.join(__dirname, "linux", "postinstall")); + scripts.forEach((script) => { + if(script.endsWith(".js")) { + require(path.join(__dirname, "linux", "postinstall", script))(); + }else if(script.endsWith(".sh")) { + execSync(`chmod +x ${path.join(__dirname, "linux", "postinstall", script)}`); + execSync(`${path.join(__dirname, "linux", "postinstall", script)}`); + + } + }) + break; + } + case "win32":{ + const scripts = fs.readdirSync(path.join(__dirname, "win32", "postinstall")); + scripts.forEach((script) => { + if(script.endsWith(".js")) { + require(path.join(__dirname, "win32", "postinstall", script))(); + }else if(script.endsWith(".bat")) { + execSync(`${path.join(__dirname, "win32", "postinstall", script)}`); + + } + }) + break; + } + default: + console.error(`Unsupported platform: ${platform}`); +} \ No newline at end of file diff --git a/build.bat b/scripts/win32/build.bat similarity index 71% rename from build.bat rename to scripts/win32/build.bat index d66153f..9dda51e 100644 --- a/build.bat +++ b/scripts/win32/build.bat @@ -1,2 +1,4 @@ @echo off +cd .. +cd .. npx electron-builder \ No newline at end of file diff --git a/scripts/win32/install.bat b/scripts/win32/install.bat new file mode 100644 index 0000000..6f325f2 --- /dev/null +++ b/scripts/win32/install.bat @@ -0,0 +1,4 @@ +@echo off +cd .. +cd .. +npm i \ No newline at end of file diff --git a/launch.bat b/scripts/win32/launch.bat similarity index 61% rename from launch.bat rename to scripts/win32/launch.bat index 29525e2..5a52753 100644 --- a/launch.bat +++ b/scripts/win32/launch.bat @@ -1,2 +1,4 @@ @echo off +cd .. +cd .. npm start \ No newline at end of file diff --git a/lineCount.bat b/scripts/win32/lineCount.bat similarity index 80% rename from lineCount.bat rename to scripts/win32/lineCount.bat index a977ad5..796d1af 100644 --- a/lineCount.bat +++ b/scripts/win32/lineCount.bat @@ -1,2 +1,4 @@ @echo off +cd .. +cd .. cloc modules front filePresets main.js \ No newline at end of file diff --git a/lint.bat b/scripts/win32/lint.bat similarity index 64% rename from lint.bat rename to scripts/win32/lint.bat index 82f4c93..d5dc0d7 100644 --- a/lint.bat +++ b/scripts/win32/lint.bat @@ -1,2 +1,4 @@ @echo off +cd .. +cd .. npx eslint . \ No newline at end of file diff --git a/pretty.bat b/scripts/win32/pretty.bat similarity index 72% rename from pretty.bat rename to scripts/win32/pretty.bat index 93c4043..c02f43e 100644 --- a/pretty.bat +++ b/scripts/win32/pretty.bat @@ -1,2 +1,4 @@ @echo off +cd .. +cd .. npx prettier . --write \ No newline at end of file From dd70810bfb85070567815ce512dddd3c855bd056 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Fri, 9 May 2025 18:34:03 -0700 Subject: [PATCH 2/4] Add compatibility to fileStringFunctions module --- front/editor/modules/fileStringFunctions.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/front/editor/modules/fileStringFunctions.js b/front/editor/modules/fileStringFunctions.js index 1be6372..b5db4db 100644 --- a/front/editor/modules/fileStringFunctions.js +++ b/front/editor/modules/fileStringFunctions.js @@ -1,16 +1,20 @@ +const path = require("path"); + function getFileNameFromLink(file) { - return file.split("\\")[file.split("\\").length - 1]; + const parts = path.normalize(file).split(path.sep); + return parts[parts.length - 1]; } function getFileDirFromLink(file) { + const parts = path.normalize(file).split(path.sep); let fileDir = ""; - file.split("\\").forEach((element, index, array) => { + parts.forEach((element, index, array) => { if (index !== array.length - 1) { if (index == 0) { fileDir = element; } else { - fileDir = `${fileDir}\\${element}`; + fileDir = path.join(fileDir, element); } } }); From 6daa084ebfbadd2f9e0de4c91b403920b197522c Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Fri, 9 May 2025 18:48:30 -0700 Subject: [PATCH 3/4] Provide OS compatibility with Path --- front/editor/editor.js | 14 ++++++-------- main.js | 4 ++-- scripts/linux/launch.sh | 0 3 files changed, 8 insertions(+), 10 deletions(-) mode change 100755 => 100644 scripts/linux/launch.sh diff --git a/front/editor/editor.js b/front/editor/editor.js index 56e07e2..84e88da 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -111,7 +111,6 @@ async function newFileDiv(file) { /////////////////////////////////////////////////////////////// function openFile(file, callback) { - console.log("Opening " + file); if (OpenedFiles.FINDQUICKINDEX("fileLink", file) === -1) { const fileFMT = OpenedFiles.FORMAT(); fileFMT.SET("fileLink", file); @@ -129,7 +128,6 @@ function openFile(file, callback) { fileFMT.SET("usesCRLF", usesCRLF); - console.log(fileData); fileFMT.SET("data", fileData); fileFMT.SET("savedFile", fileData); OpenedFiles.PUSH(fileFMT); @@ -607,8 +605,8 @@ async function refreshEditor() { const option = document.createElement("option"); option.value = e.fileLink; - const splittedFileLink = e.fileLink.split("\\"); - option.innerHTML = `${splittedFileLink[splittedFileLink.length - 2]}\\${splittedFileLink[splittedFileLink.length - 1]}`; + const splittedFileLink = path.normalize(e.fileLink).split(path.sep); + option.innerHTML = path.join(splittedFileLink[splittedFileLink.length - 2], splittedFileLink[splittedFileLink.length - 1]) document.getElementById("windowPicker").appendChild(option); }); @@ -746,7 +744,7 @@ document.addEventListener("DOMContentLoaded", () => { }); files.forEach((element) => { const option = document.createElement("option"); - option.value = `${element.parentPath}\\${element.name}`; + option.value = path.join(element.parentPath, element.name); option.innerHTML = element.name; list.appendChild(option); @@ -783,10 +781,10 @@ createBtn.addEventListener("click", async () => { filedata = fs.readFileSync(args.preset, { encoding: "utf-8" }); } - fs.writeFileSync(`${args.dir}\\${args.name}`, filedata); + fs.writeFileSync(path.join(args.dir, args.name), filedata); - openFile(`${args.dir}\\${args.name}`, () => { - loadFileIntoEditor(`${args.dir}\\${args.name}`); + openFile(path.join(args.dir, args.name), () => { + loadFileIntoEditor(path.join(args.dir, args.name)); }); document.getElementById("filenameField").value = ""; dir = null; diff --git a/main.js b/main.js index 7a11ad6..ef1be49 100644 --- a/main.js +++ b/main.js @@ -44,8 +44,8 @@ const createWindow = () => { height: 600, minWidth: 600, minHeight: 400, + autoHideMenuBar: true, // Comment this line on development webPreferences: { nodeIntegration: true, contextIsolation: false } - //autoHideMenuBar: true // Commented out for debugging }); mainWindow.on("closed", () => { @@ -175,7 +175,7 @@ ipcMain.handle("get-dir", async () => { }); if (result.canceled == false && result.filePaths.length == 1) { - return { dir: result.filePaths, status: 0 }; + return { dir: result.filePaths[0], status: 0 }; } else { return { dir: null, status: -1 }; } diff --git a/scripts/linux/launch.sh b/scripts/linux/launch.sh old mode 100755 new mode 100644 From ad8076cceba460f5d35c7197b054621d1af822ce Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 10 May 2025 01:49:18 +0000 Subject: [PATCH 4/4] WF: Lint and Prettier: Bugfix/linux build states lack of permissions upon opening a viewer window --- front/editor/editor.js | 5 +- scripts/linux/postinstall/fix-sandbox.js | 43 +++++---- scripts/postinstall.js | 118 +++++++++++++---------- 3 files changed, 91 insertions(+), 75 deletions(-) diff --git a/front/editor/editor.js b/front/editor/editor.js index 84e88da..04c3b46 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -606,7 +606,10 @@ async function refreshEditor() { const option = document.createElement("option"); option.value = e.fileLink; const splittedFileLink = path.normalize(e.fileLink).split(path.sep); - option.innerHTML = path.join(splittedFileLink[splittedFileLink.length - 2], splittedFileLink[splittedFileLink.length - 1]) + option.innerHTML = path.join( + splittedFileLink[splittedFileLink.length - 2], + splittedFileLink[splittedFileLink.length - 1] + ); document.getElementById("windowPicker").appendChild(option); }); diff --git a/scripts/linux/postinstall/fix-sandbox.js b/scripts/linux/postinstall/fix-sandbox.js index b0c46b8..ddcb202 100644 --- a/scripts/linux/postinstall/fix-sandbox.js +++ b/scripts/linux/postinstall/fix-sandbox.js @@ -3,27 +3,28 @@ const { execSync } = require("child_process"); const path = require("path"); const fs = require("fs"); - module.exports = function () { - if (process.platform === "linux") { - // Correct path to node_modules/electron/dist/chrome-sandbox - const sandboxPath = path.resolve( - __dirname, - "../../../node_modules/electron/dist/chrome-sandbox" - ); + if (process.platform === "linux") { + // Correct path to node_modules/electron/dist/chrome-sandbox + const sandboxPath = path.resolve( + __dirname, + "../../../node_modules/electron/dist/chrome-sandbox" + ); - console.log("Fixing sandbox permissions... (sudo password may be required)"); + console.log( + "Fixing sandbox permissions... (sudo password may be required)" + ); - if (fs.existsSync(sandboxPath)) { - try { - execSync(`sudo chown root ${sandboxPath}`); - execSync(`sudo chmod 4755 ${sandboxPath}`); - console.log("✔ Sandbox permissions fixed."); - } catch (err) { - console.warn("⚠ Failed to fix sandbox permissions:", err.message); - } - } else { - console.warn("⚠ Sandbox file not found at:", sandboxPath); - } - } -} \ No newline at end of file + if (fs.existsSync(sandboxPath)) { + try { + execSync(`sudo chown root ${sandboxPath}`); + execSync(`sudo chmod 4755 ${sandboxPath}`); + console.log("✔ Sandbox permissions fixed."); + } catch (err) { + console.warn("⚠ Failed to fix sandbox permissions:", err.message); + } + } else { + console.warn("⚠ Sandbox file not found at:", sandboxPath); + } + } +}; diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 1b9f71e..4d8e415 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -8,56 +8,68 @@ const platform = os.platform(); const arch = os.arch(); switch (platform) { - case "darwin": - // macOS specific code - switch (arch) { - case "x64": { - const scripts = fs.readdirSync(path.join(__dirname, "darwin-x64", "postinstall")); - scripts.forEach((script) => { - if(script.endsWith(".js")) { - require(path.join(__dirname, "darwin-x64", "postinstall", script))(); - } - }) - break; - } - case "arm64": { - const scripts = fs.readdirSync(path.join(__dirname, "darwin-arm64", "postinstall")); - scripts.forEach((script) => { - if(script.endsWith(".js")) { - require(path.join(__dirname, "darwin-arm64", "postinstall", script))(); - } - }) - break; - } - default: - console.log("Are you still using PowerPC?"); - } - break; - case "linux": { - const scripts = fs.readdirSync(path.join(__dirname, "linux", "postinstall")); - scripts.forEach((script) => { - if(script.endsWith(".js")) { - require(path.join(__dirname, "linux", "postinstall", script))(); - }else if(script.endsWith(".sh")) { - execSync(`chmod +x ${path.join(__dirname, "linux", "postinstall", script)}`); - execSync(`${path.join(__dirname, "linux", "postinstall", script)}`); - - } - }) - break; - } - case "win32":{ - const scripts = fs.readdirSync(path.join(__dirname, "win32", "postinstall")); - scripts.forEach((script) => { - if(script.endsWith(".js")) { - require(path.join(__dirname, "win32", "postinstall", script))(); - }else if(script.endsWith(".bat")) { - execSync(`${path.join(__dirname, "win32", "postinstall", script)}`); - - } - }) - break; - } - default: - console.error(`Unsupported platform: ${platform}`); -} \ No newline at end of file + case "darwin": + // macOS specific code + switch (arch) { + case "x64": { + const scripts = fs.readdirSync( + path.join(__dirname, "darwin-x64", "postinstall") + ); + scripts.forEach((script) => { + if (script.endsWith(".js")) { + require( + path.join(__dirname, "darwin-x64", "postinstall", script) + )(); + } + }); + break; + } + case "arm64": { + const scripts = fs.readdirSync( + path.join(__dirname, "darwin-arm64", "postinstall") + ); + scripts.forEach((script) => { + if (script.endsWith(".js")) { + require( + path.join(__dirname, "darwin-arm64", "postinstall", script) + )(); + } + }); + break; + } + default: + console.log("Are you still using PowerPC?"); + } + break; + case "linux": { + const scripts = fs.readdirSync( + path.join(__dirname, "linux", "postinstall") + ); + scripts.forEach((script) => { + if (script.endsWith(".js")) { + require(path.join(__dirname, "linux", "postinstall", script))(); + } else if (script.endsWith(".sh")) { + execSync( + `chmod +x ${path.join(__dirname, "linux", "postinstall", script)}` + ); + execSync(`${path.join(__dirname, "linux", "postinstall", script)}`); + } + }); + break; + } + case "win32": { + const scripts = fs.readdirSync( + path.join(__dirname, "win32", "postinstall") + ); + scripts.forEach((script) => { + if (script.endsWith(".js")) { + require(path.join(__dirname, "win32", "postinstall", script))(); + } else if (script.endsWith(".bat")) { + execSync(`${path.join(__dirname, "win32", "postinstall", script)}`); + } + }); + break; + } + default: + console.error(`Unsupported platform: ${platform}`); +}