From d64b418d00dabf55fcba4e2e69648da71243b7ce Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Sat, 3 May 2025 23:34:07 -0700 Subject: [PATCH 1/7] Start tracking displays with fileLinks instead of windows --- front/editor/editor.js | 48 ++++++++++++++++++++++++--------- main.js | 61 ++++++++++++++++++------------------------ 2 files changed, 61 insertions(+), 48 deletions(-) diff --git a/front/editor/editor.js b/front/editor/editor.js index 8cd0253..6426c69 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -382,11 +382,9 @@ document.addEventListener("keydown", async (event) => { } } else if (event.key.toLowerCase() === "w") { event.preventDefault(); + if (currentFile === null) return; if (event.shiftKey) { - if ( - currentFile === null || - (!currentFile.endsWith(".html") && !currentFile.endsWith(".htm")) - ) { + if (!currentFile.endsWith(".html") && !currentFile.endsWith(".htm")) { ipcRenderer.send("new-window"); } else { ipcRenderer.invoke("new-window-set", currentFile).then((response) => { @@ -575,8 +573,19 @@ async function refreshEditor() { }); OpenedDisplays.forEach((e) => { + Array.from(document.getElementById("windowPicker").children).forEach( + (child) => { + child.remove(); + } + ); + // + const noOption = document.createElement("option"); + noOption.value = "none"; + noOption.innerHTML = "(none)"; + document.getElementById("windowPicker").appendChild(noOption); + const option = document.createElement("option"); - option.value = e.window; + option.value = e.fileLink; const splittedFileLink = e.fileLink.split("\\"); option.innerHTML = `${splittedFileLink[splittedFileLink.length - 2]}\\${splittedFileLink[splittedFileLink.length - 1]}`; document.getElementById("windowPicker").appendChild(option); @@ -746,8 +755,22 @@ createBtn.addEventListener("click", () => { if (args.dir == null || args.name == null || args.preset == null) { alert("Argument missing."); } else { - ipcRenderer.invoke("createFile", args).then((response) => { - if (response == 0) { + let filedata = ""; + + if (args.preset !== "none") { + filedata = fs.readFileSync(args.preset, { encoding: "utf-8" }); + } + + let ans = 0; + + fs.writeFile(`${args.dir}\\${args.name}`, filedata, function (err) { + if (err) { + ans = err; + throw err; + } + }); + + if (ans == 0) { openFile(`${args.dir}\\${args.name}`, () => { loadFileIntoEditor(`${args.dir}\\${args.name}`); }); @@ -759,7 +782,6 @@ createBtn.addEventListener("click", () => { } else { alert("Error in file creation"); } - }); } }); @@ -770,11 +792,9 @@ createBtn.addEventListener("click", () => { const openViewerBtn = document.getElementById("OpenViewerBtn"); openViewerBtn.addEventListener("click", (event) => { + if (currentFile === null) return; if (event.shiftKey) { - if ( - currentFile === null || - (!currentFile.endsWith(".html") && !currentFile.endsWith(".htm")) - ) { + if (!currentFile.endsWith(".html") && !currentFile.endsWith(".htm")) { ipcRenderer.send("new-window"); } else { ipcRenderer.invoke("new-window-set", currentFile).then((response) => { @@ -807,7 +827,7 @@ cancelDisplayPickBtn.addEventListener("click", () => { const pickWindowBtn = document.getElementById("pickWindowBtn"); pickWindowBtn.addEventListener("click", () => { - if (document.getElementById("windowPicker").value != "none") { + if (document.getElementById("windowPicker").value !== "none") { OpenedFiles.SET( OpenedFiles.FINDQUICKINDEX("fileLink", currentFile), "linkedDisplay", @@ -815,6 +835,8 @@ pickWindowBtn.addEventListener("click", () => { ); pickOpenedDisplayDialog.close(); document.getElementById("windowPicker").value = "none"; + } else { + pickOpenedDisplayDialog.close(); } }); diff --git a/main.js b/main.js index 1b72816..05d3bcc 100644 --- a/main.js +++ b/main.js @@ -4,9 +4,8 @@ const { BrowserWindow, ipcMain, dialog, - webContents } = require("electron"); -const fs = require("fs"); + const needle = require("needle-db"); // Setup OpenedDisplaysDB @@ -27,6 +26,7 @@ const createWindow = () => { minWidth: 600, minHeight: 400, webPreferences: { nodeIntegration: true, contextIsolation: false } + //autoHideMenuBar: true // Commented out for debugging }); window.on("closed", () => { @@ -64,7 +64,11 @@ ipcMain.on("new-window", async () => { newWdwFMT.SET("fileLink", result.filePaths[0]); newWdwFMT.SET( "window", - launchWindow(result.filePaths[0], { width: 500, height: 500 }) + launchWindow(result.filePaths[0], { + width: 500, + height: 500, + webPreferences: { nodeIntegration: true } + }) ); openedDisplays.PUSH(newWdwFMT); @@ -95,7 +99,14 @@ ipcMain.handle("new-window-set", async (event, args) => { const newWdwFMT = openedDisplays.FORMAT(); newWdwFMT.SET("fileLink", args); - newWdwFMT.SET("window", launchWindow(args, { width: 500, height: 500 })); + newWdwFMT.SET( + "window", + launchWindow(args, { + width: 500, + height: 500, + webPreferences: { nodeIntegration: true } + }) + ); openedDisplays.PUSH(newWdwFMT); @@ -105,7 +116,10 @@ ipcMain.handle("new-window-set", async (event, args) => { openedDisplays.DELETE(openedDisplays.FINDQUICKINDEX("fileLink", args)); }); - return openedDisplays.FINDQUICKINDEX("fileLink", args); + return openedDisplays.READ( + openedDisplays.FINDQUICKINDEX("fileLink", args), + "fileLink" + ); }); ipcMain.handle("filePickerDialog", async () => { @@ -148,25 +162,6 @@ ipcMain.handle("get-dir", async () => { } }); -ipcMain.handle("createFile", (event, args) => { - let filedata = ""; - - if (args.preset !== "none") { - filedata = fs.readFileSync(args.preset, { encoding: "utf-8" }); - } - - let ans = 0; - - fs.writeFile(`${args.dir}\\${args.name}`, filedata, function (err) { - if (err) { - ans = err; - throw err; - } - }); - - return ans; -}); - ipcMain.on("closeWindow", (event) => { const senderWindow = BrowserWindow.getAllWindows().find( (win) => win.webContents === event.sender @@ -199,15 +194,6 @@ ipcMain.handle("pickOpenedDisplay", async () => { return openedDisplaysReduced; }); -ipcMain.on( - "connectWindowSelection", - (event, value, callerFile, CallerWindow) => { - webContents - .fromId(CallerWindow) - .send("syncLinkedDisplay", callerFile, value); - } -); - ipcMain.on("printOpenedDisplays", () => { // Function for debugging @@ -216,6 +202,11 @@ ipcMain.on("printOpenedDisplays", () => { ipcMain.on("restartDisplay", (event, args) => { openedDisplays - .READ(args, "window") - .loadFile(openedDisplays.READ(args, "fileLink")); + .READ(openedDisplays.FINDQUICKINDEX("fileLink", args), "window") + .loadFile( + openedDisplays.READ( + openedDisplays.FINDQUICKINDEX("fileLink", args), + "fileLink" + ) + ); }); From 889b23423337d24783926dcb8040b159eb9bd816 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Sat, 3 May 2025 23:44:14 -0700 Subject: [PATCH 2/7] Add some order --- front/editor/editor.js | 2 +- main.js | 172 +++++++++++++++++++++++++---------------- 2 files changed, 107 insertions(+), 67 deletions(-) diff --git a/front/editor/editor.js b/front/editor/editor.js index 6426c69..58bb5d3 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -1,6 +1,6 @@ /* /////////////////////////////////////////////////////////////// - Index - Search with Ctrl + F (VSCode) + editor.js / Index - Search with Ctrl + F (VSCode) /////////////////////////////////////////////////////////////// - Module Import diff --git a/main.js b/main.js index 05d3bcc..2491022 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,24 @@ -// Import libraries +/* +/////////////////////////////////////////////////////////////// + main.js / Index - Search with Ctrl + F (VSCode) +/////////////////////////////////////////////////////////////// + + - Module Import + - Setup Needle DB + - Setup Main Editor + - Handle New Window Creation + - Handle file picking + - Handle directory picking + - Handle window closures + - Handle Display Restart + - Others + +*/ + +/////////////////////////////////////////////////////////////// +// Module Import +/////////////////////////////////////////////////////////////// + const { app, BrowserWindow, @@ -6,19 +26,22 @@ const { dialog, } = require("electron"); -const needle = require("needle-db"); +const launchWindow = require("./modules/launchWindow"); -// Setup OpenedDisplaysDB +/////////////////////////////////////////////////////////////// +// Setup Needle DB +/////////////////////////////////////////////////////////////// +const needle = require("needle-db"); const openedDisplays = new needle(); openedDisplays.NEWCOLUMN("fileLink"); openedDisplays.NEWCOLUMN("window"); -// Import Dependencies -const launchWindow = require("./modules/launchWindow"); +/////////////////////////////////////////////////////////////// +// Setup Main Editor +/////////////////////////////////////////////////////////////// -// Setup Window const createWindow = () => { const window = launchWindow("./front/editor/editor.html", { width: 600, @@ -45,6 +68,38 @@ app.on("window-all-closed", () => { if (process.platform !== "darwin") app.quit(); }); +/////////////////////////////////////////////////////////////// +// Handle New Window Creation +// - Handle set window creation +/////////////////////////////////////////////////////////////// + +function createNewDisplay(fileLink){ + const newWdwFMT = openedDisplays.FORMAT(); + + newWdwFMT.SET("fileLink", fileLink); + newWdwFMT.SET( + "window", + launchWindow(fileLink, { + width: 500, + height: 500, + webPreferences: { nodeIntegration: true } + }) + ); + + openedDisplays.PUSH(newWdwFMT); + + openedDisplays + .READ( + openedDisplays.FINDQUICKINDEX("fileLink", fileLink), + "window" + ) + .webContents.on("destroyed", () => { + openedDisplays.DELETE( + openedDisplays.FINDQUICKINDEX("fileLink", fileLink) + ); + }); +} + ipcMain.on("new-window", async () => { const result = await dialog.showOpenDialog({ properties: ["openFile"], @@ -59,33 +114,14 @@ ipcMain.on("new-window", async () => { }); } if (!result.canceled && result.filePaths && result.filePaths[0] && flag) { - const newWdwFMT = openedDisplays.FORMAT(); - - newWdwFMT.SET("fileLink", result.filePaths[0]); - newWdwFMT.SET( - "window", - launchWindow(result.filePaths[0], { - width: 500, - height: 500, - webPreferences: { nodeIntegration: true } - }) - ); - - openedDisplays.PUSH(newWdwFMT); - - openedDisplays - .READ( - openedDisplays.FINDQUICKINDEX("fileLink", result.filePaths[0]), - "window" - ) - .webContents.on("destroyed", () => { - openedDisplays.DELETE( - openedDisplays.FINDQUICKINDEX("fileLink", result.filePaths[0]) - ); - }); + createNewDisplay(result.filePaths[0]); } }); +/////////////////////////////////////////////////////////////// +// Handle New Window Creation: Handle set window creation +/////////////////////////////////////////////////////////////// + ipcMain.handle("new-window-set", async (event, args) => { var flag = true; if (openedDisplays.GETJSONDATA().length > 0) { @@ -96,32 +132,14 @@ ipcMain.handle("new-window-set", async (event, args) => { }); } if (flag == false) return -1; - const newWdwFMT = openedDisplays.FORMAT(); - - newWdwFMT.SET("fileLink", args); - newWdwFMT.SET( - "window", - launchWindow(args, { - width: 500, - height: 500, - webPreferences: { nodeIntegration: true } - }) - ); - - openedDisplays.PUSH(newWdwFMT); - - openedDisplays - .READ(openedDisplays.FINDQUICKINDEX("fileLink", args), "window") - .webContents.on("destroyed", () => { - openedDisplays.DELETE(openedDisplays.FINDQUICKINDEX("fileLink", args)); - }); - - return openedDisplays.READ( - openedDisplays.FINDQUICKINDEX("fileLink", args), - "fileLink" - ); + createNewDisplay(args); + return args }); +/////////////////////////////////////////////////////////////// +// Handle file picking +/////////////////////////////////////////////////////////////// + ipcMain.handle("filePickerDialog", async () => { const result = await dialog.showOpenDialog({ properties: ["openFile"], @@ -150,6 +168,10 @@ ipcMain.handle("filePickerDialog", async () => { return result.filePaths[0]; }); +/////////////////////////////////////////////////////////////// +// Handle directory picking +/////////////////////////////////////////////////////////////// + ipcMain.handle("get-dir", async () => { const result = await dialog.showOpenDialog({ properties: ["openDirectory"] @@ -162,6 +184,11 @@ ipcMain.handle("get-dir", async () => { } }); +/////////////////////////////////////////////////////////////// +// Handle window closures +// - Force Close +/////////////////////////////////////////////////////////////// + ipcMain.on("closeWindow", (event) => { const senderWindow = BrowserWindow.getAllWindows().find( (win) => win.webContents === event.sender @@ -172,6 +199,11 @@ ipcMain.on("closeWindow", (event) => { } }); +/////////////////////////////////////////////////////////////// +// Handle window closure: Force Close +/////////////////////////////////////////////////////////////// + + ipcMain.on("forceCloseWindow", (event) => { const senderWindow = BrowserWindow.getAllWindows().find( (win) => win.webContents === event.sender @@ -182,6 +214,25 @@ ipcMain.on("forceCloseWindow", (event) => { } }); +/////////////////////////////////////////////////////////////// +// Handle Display Restart +/////////////////////////////////////////////////////////////// + +ipcMain.on("restartDisplay", (event, args) => { + openedDisplays + .READ(openedDisplays.FINDQUICKINDEX("fileLink", args), "window") + .loadFile( + openedDisplays.READ( + openedDisplays.FINDQUICKINDEX("fileLink", args), + "fileLink" + ) + ); +}); + +/////////////////////////////////////////////////////////////// +// Others +/////////////////////////////////////////////////////////////// + ipcMain.on("printOnBackConsole", (event, args) => { console.log(args); }); @@ -198,15 +249,4 @@ ipcMain.on("printOpenedDisplays", () => { // Function for debugging console.log(openedDisplays.GETJSONDATA()); -}); - -ipcMain.on("restartDisplay", (event, args) => { - openedDisplays - .READ(openedDisplays.FINDQUICKINDEX("fileLink", args), "window") - .loadFile( - openedDisplays.READ( - openedDisplays.FINDQUICKINDEX("fileLink", args), - "fileLink" - ) - ); -}); +}); \ No newline at end of file From f529f017253642eb19dcbf60c08aca066520e974 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Mon, 5 May 2025 00:22:31 -0700 Subject: [PATCH 3/7] Add TODO --- main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 2491022..004653d 100644 --- a/main.js +++ b/main.js @@ -53,7 +53,6 @@ const createWindow = () => { }); window.on("closed", () => { - // TODO: Save editor state app.quit(); }); }; @@ -96,6 +95,9 @@ function createNewDisplay(fileLink){ .webContents.on("destroyed", () => { openedDisplays.DELETE( openedDisplays.FINDQUICKINDEX("fileLink", fileLink) + + // TODO: Send an event to the editor window to clear any linked windows + ); }); } From 6c622de7a3e9bff4d0827c60452aef7086fca042 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Mon, 5 May 2025 00:51:26 -0700 Subject: [PATCH 4/7] Rework Highlighter --- build.bat | 2 ++ electron-builder.json | 4 ++-- front/editor/editor.html | 1 - front/editor/editor.js | 13 +++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 build.bat diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..d66153f --- /dev/null +++ b/build.bat @@ -0,0 +1,2 @@ +@echo off +npx electron-builder \ No newline at end of file diff --git a/electron-builder.json b/electron-builder.json index 48ceb75..30fc9b3 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -4,8 +4,8 @@ "directories": { "output": "dist" }, - "files": ["!filePresets/**"], - "extraResources": [{ "from": "filePresets", "to": "../filePresets" }], + "files": ["!filePresets/**", "!front/editor/highlighter.css"], + "extraResources": [{ "from": "filePresets", "to": "../filePresets" }, { "from": "front/editor/highlighter.css", "to": "../front/editor/highlighter.css" }], "icon": "resources/icon/icon.ico", "win": { "target": "zip", diff --git a/front/editor/editor.html b/front/editor/editor.html index c9a3e4e..776b367 100644 --- a/front/editor/editor.html +++ b/front/editor/editor.html @@ -4,7 +4,6 @@ WebBox - diff --git a/front/editor/editor.js b/front/editor/editor.js index 58bb5d3..754970c 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -22,6 +22,7 @@ - New File Dialog - Open Viewer - Pick Opened Display Dialog + - Load Highlighter - Others */ @@ -41,6 +42,7 @@ const { const highlighter = require("./highlight"); const { getCaretPosition, setCaretPosition } = require("./modules/caret"); const fs = require("fs"); +const path = require("path"); /////////////////////////////////////////////////////////////// // Setup Needle DB @@ -840,6 +842,17 @@ pickWindowBtn.addEventListener("click", () => { } }); +////////////////////////////////////////////////////////// +// Load Highlighter +///////////////////////////////////////////////////////// + +const cssPath = path.join(process.cwd(), "front", "editor", "highlighter.css"); + +const link = document.createElement("link"); +link.rel = "stylesheet"; +link.href = `file://${cssPath}`; +document.head.appendChild(link); + ///////////////////////////////////////////////////////// // Others ///////////////////////////////////////////////////////// From afb8052dfa8b395d6598bf4b4cc4cff1fc1dbd84 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Mon, 5 May 2025 00:59:06 -0700 Subject: [PATCH 5/7] Unlink Opened Editors --- front/editor/editor.js | 13 +++++++++++++ main.js | 10 ++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/front/editor/editor.js b/front/editor/editor.js index 754970c..6d83b52 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -23,6 +23,7 @@ - Open Viewer - Pick Opened Display Dialog - Load Highlighter + - Handle Window Deletion - Others */ @@ -853,6 +854,18 @@ link.rel = "stylesheet"; link.href = `file://${cssPath}`; document.head.appendChild(link); +////////////////////////////////////////////////////////// +// Handle Window Deletion +///////////////////////////////////////////////////////// + +ipcRenderer.on("deleteWindow", (event, fileLink) => { + const linkedEditor = OpenedFiles.FINDQUICKINDEX("linkedDisplay", fileLink); + + if(linkedEditor !== -1) { + OpenedFiles.SET(linkedEditor, "linkedDisplay", null); + } +}); + ///////////////////////////////////////////////////////// // Others ///////////////////////////////////////////////////////// diff --git a/main.js b/main.js index 004653d..5e1bb25 100644 --- a/main.js +++ b/main.js @@ -41,9 +41,9 @@ openedDisplays.NEWCOLUMN("window"); /////////////////////////////////////////////////////////////// // Setup Main Editor /////////////////////////////////////////////////////////////// - +let mainWindow = null; const createWindow = () => { - const window = launchWindow("./front/editor/editor.html", { + mainWindow = launchWindow("./front/editor/editor.html", { width: 600, height: 600, minWidth: 600, @@ -52,7 +52,7 @@ const createWindow = () => { //autoHideMenuBar: true // Commented out for debugging }); - window.on("closed", () => { + mainWindow.on("closed", () => { app.quit(); }); }; @@ -95,10 +95,8 @@ function createNewDisplay(fileLink){ .webContents.on("destroyed", () => { openedDisplays.DELETE( openedDisplays.FINDQUICKINDEX("fileLink", fileLink) - - // TODO: Send an event to the editor window to clear any linked windows - ); + mainWindow.webContents.send("deleteWindow", fileLink); }); } From c30026da8998d2bae898e89fc64b828ea4d58715 Mon Sep 17 00:00:00 2001 From: Ethan Mahlstedt Date: Mon, 5 May 2025 01:02:40 -0700 Subject: [PATCH 6/7] Contemplates more than one editor linked to the same display --- front/editor/editor.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/front/editor/editor.js b/front/editor/editor.js index 6d83b52..2d8ee8a 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -859,11 +859,13 @@ document.head.appendChild(link); ///////////////////////////////////////////////////////// ipcRenderer.on("deleteWindow", (event, fileLink) => { - const linkedEditor = OpenedFiles.FINDQUICKINDEX("linkedDisplay", fileLink); + const linkedEditors = OpenedFiles.SEARCH("linkedDisplay", fileLink); + + + linkedEditors.forEach((e) => { + OpenedFiles.SET(e, "linkedDisplay", null); + }); - if(linkedEditor !== -1) { - OpenedFiles.SET(linkedEditor, "linkedDisplay", null); - } }); ///////////////////////////////////////////////////////// From 56bfae4b0aaddb78fc94513d7c5f59121e5b65bf Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Mon, 5 May 2025 08:06:25 +0000 Subject: [PATCH 7/7] WF: Lint and Prettier: Bugfix/viewer and files dont unsync when closed --- electron-builder.json | 8 ++++++- front/editor/editor.js | 52 ++++++++++++++++++++---------------------- main.js | 19 ++++----------- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/electron-builder.json b/electron-builder.json index 30fc9b3..4188f8e 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -5,7 +5,13 @@ "output": "dist" }, "files": ["!filePresets/**", "!front/editor/highlighter.css"], - "extraResources": [{ "from": "filePresets", "to": "../filePresets" }, { "from": "front/editor/highlighter.css", "to": "../front/editor/highlighter.css" }], + "extraResources": [ + { "from": "filePresets", "to": "../filePresets" }, + { + "from": "front/editor/highlighter.css", + "to": "../front/editor/highlighter.css" + } + ], "icon": "resources/icon/icon.ico", "win": { "target": "zip", diff --git a/front/editor/editor.js b/front/editor/editor.js index 2d8ee8a..28bccb4 100644 --- a/front/editor/editor.js +++ b/front/editor/editor.js @@ -758,33 +758,33 @@ createBtn.addEventListener("click", () => { if (args.dir == null || args.name == null || args.preset == null) { alert("Argument missing."); } else { - let filedata = ""; - - if (args.preset !== "none") { - filedata = fs.readFileSync(args.preset, { encoding: "utf-8" }); - } - - let ans = 0; - - fs.writeFile(`${args.dir}\\${args.name}`, filedata, function (err) { - if (err) { - ans = err; - throw err; - } - }); + let filedata = ""; - if (ans == 0) { - openFile(`${args.dir}\\${args.name}`, () => { - loadFileIntoEditor(`${args.dir}\\${args.name}`); - }); - document.getElementById("filenameField").value = ""; - dir = null; - document.getElementById("fileDirLbl").innerHTML = "No folder selected"; - document.getElementById("presetPicker").value = "none"; - document.getElementById("newFileDialog").close(); - } else { - alert("Error in file creation"); + if (args.preset !== "none") { + filedata = fs.readFileSync(args.preset, { encoding: "utf-8" }); + } + + let ans = 0; + + fs.writeFile(`${args.dir}\\${args.name}`, filedata, function (err) { + if (err) { + ans = err; + throw err; } + }); + + if (ans == 0) { + openFile(`${args.dir}\\${args.name}`, () => { + loadFileIntoEditor(`${args.dir}\\${args.name}`); + }); + document.getElementById("filenameField").value = ""; + dir = null; + document.getElementById("fileDirLbl").innerHTML = "No folder selected"; + document.getElementById("presetPicker").value = "none"; + document.getElementById("newFileDialog").close(); + } else { + alert("Error in file creation"); + } } }); @@ -861,11 +861,9 @@ document.head.appendChild(link); ipcRenderer.on("deleteWindow", (event, fileLink) => { const linkedEditors = OpenedFiles.SEARCH("linkedDisplay", fileLink); - linkedEditors.forEach((e) => { OpenedFiles.SET(e, "linkedDisplay", null); }); - }); ///////////////////////////////////////////////////////// diff --git a/main.js b/main.js index 5e1bb25..c59f556 100644 --- a/main.js +++ b/main.js @@ -19,12 +19,7 @@ // Module Import /////////////////////////////////////////////////////////////// -const { - app, - BrowserWindow, - ipcMain, - dialog, -} = require("electron"); +const { app, BrowserWindow, ipcMain, dialog } = require("electron"); const launchWindow = require("./modules/launchWindow"); @@ -72,7 +67,7 @@ app.on("window-all-closed", () => { // - Handle set window creation /////////////////////////////////////////////////////////////// -function createNewDisplay(fileLink){ +function createNewDisplay(fileLink) { const newWdwFMT = openedDisplays.FORMAT(); newWdwFMT.SET("fileLink", fileLink); @@ -88,10 +83,7 @@ function createNewDisplay(fileLink){ openedDisplays.PUSH(newWdwFMT); openedDisplays - .READ( - openedDisplays.FINDQUICKINDEX("fileLink", fileLink), - "window" - ) + .READ(openedDisplays.FINDQUICKINDEX("fileLink", fileLink), "window") .webContents.on("destroyed", () => { openedDisplays.DELETE( openedDisplays.FINDQUICKINDEX("fileLink", fileLink) @@ -133,7 +125,7 @@ ipcMain.handle("new-window-set", async (event, args) => { } if (flag == false) return -1; createNewDisplay(args); - return args + return args; }); /////////////////////////////////////////////////////////////// @@ -203,7 +195,6 @@ ipcMain.on("closeWindow", (event) => { // Handle window closure: Force Close /////////////////////////////////////////////////////////////// - ipcMain.on("forceCloseWindow", (event) => { const senderWindow = BrowserWindow.getAllWindows().find( (win) => win.webContents === event.sender @@ -249,4 +240,4 @@ ipcMain.on("printOpenedDisplays", () => { // Function for debugging console.log(openedDisplays.GETJSONDATA()); -}); \ No newline at end of file +});