diff --git a/front/editor/editor.js b/front/editor/editor.js index 56e07e2..04c3b46 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,11 @@ 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 +747,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 +784,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/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); } } }); 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/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/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 100644 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..ddcb202 --- /dev/null +++ b/scripts/linux/postinstall/fix-sandbox.js @@ -0,0 +1,30 @@ +// 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); + } + } +}; diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 0000000..4d8e415 --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,75 @@ +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}`); +} 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