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.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);
|
menu.load(window);
|
||||||
systemTray.load(menu.menuStruct);
|
systemTray.load(menu.menuStruct);
|
||||||
terminal.load(window);
|
terminal.load(window);
|
||||||
|
|||||||
25
newton/fs.js
25
newton/fs.js
@@ -185,10 +185,33 @@ const closeFile = (fpath) => {
|
|||||||
unwatchFile(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 = {
|
module.exports = {
|
||||||
newtonFs: {
|
newtonFs: {
|
||||||
|
CONFIG_PATH: CONFIG_PATH,
|
||||||
setWindow: setWindow,
|
setWindow: setWindow,
|
||||||
chooseFolder: chooseFolder,
|
chooseFolder: chooseFolder,
|
||||||
openFiles: openFiles,
|
openFiles: openFiles,
|
||||||
@@ -200,6 +223,8 @@ module.exports = {
|
|||||||
getLspConfigData: getLspConfigData,
|
getLspConfigData: getLspConfigData,
|
||||||
getSettingsConfigData: getSettingsConfigData,
|
getSettingsConfigData: getSettingsConfigData,
|
||||||
saveSettingsConfigData: saveSettingsConfigData,
|
saveSettingsConfigData: saveSettingsConfigData,
|
||||||
|
readAndInjectJS: readAndInjectJS,
|
||||||
|
readAndInjectCSS: readAndInjectCSS,
|
||||||
loadFilesWatcher: loadFilesWatcher,
|
loadFilesWatcher: loadFilesWatcher,
|
||||||
unwatchFile: unwatchFile,
|
unwatchFile: unwatchFile,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user