Adding pre-dynamic load of css and js
This commit is contained in:
@@ -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);
|
||||
|
||||
25
newton/fs.js
25
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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user