From a4765952bfd337cd24a30010b4908913f4910f09 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Thu, 27 Nov 2025 23:01:55 -0600 Subject: [PATCH] Adding pre-dynamic load of css and js --- newton/app.js | 14 ++++++++++++++ newton/fs.js | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/newton/app.js b/newton/app.js index f60a6eb..218817a 100644 --- a/newton/app.js +++ b/newton/app.js @@ -54,6 +54,20 @@ const createWindow = (startType = "build", debug = false, args = []) => { window.webContents.send('load-files', args); }); + window.webContents.on('did-finish-load', () => { + const cssFiles = [ + path.join(newtonFs.CONFIG_PATH, 'override.css') + ]; + + const jsFiles = [ + // path.join(newtonFs.CONFIG_PATH, 'scripts', 'script1.js'), + // path.join(newtonFs.CONFIG_PATH, 'scripts', 'script2.js') + ]; + + cssFiles.forEach(cssFile => newtonFs.readAndInjectCSS(window, cssFile)); + jsFiles.forEach(jsFile => newtonFs.readAndInjectJS(window, jsFile)); + }); + menu.load(window); systemTray.load(menu.menuStruct); terminal.load(window); diff --git a/newton/fs.js b/newton/fs.js index e1f879d..acab341 100644 --- a/newton/fs.js +++ b/newton/fs.js @@ -185,10 +185,33 @@ const closeFile = (fpath) => { unwatchFile(fpath); } +const readAndInjectCSS = (window, filePath) => { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.error(`Error reading CSS file: ${filePath}`, err); + return; + } + + window.webContents.insertCSS(data); + }); +} + +const readAndInjectJS = (window, filePath) => { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.error(`Error reading JS file: ${filePath}`, err); + return; + } + + window.webContents.executeJavaScript(data); + }); +} + module.exports = { newtonFs: { + CONFIG_PATH: CONFIG_PATH, setWindow: setWindow, chooseFolder: chooseFolder, openFiles: openFiles, @@ -200,6 +223,8 @@ module.exports = { getLspConfigData: getLspConfigData, getSettingsConfigData: getSettingsConfigData, saveSettingsConfigData: saveSettingsConfigData, + readAndInjectJS: readAndInjectJS, + readAndInjectCSS: readAndInjectCSS, loadFilesWatcher: loadFilesWatcher, unwatchFile: unwatchFile, }