Ready to inject CSS in app

This commit is contained in:
Pierre HUBERT 2019-02-11 20:12:17 +01:00
parent 250a4544ab
commit 0ec6cf80db
2 changed files with 22 additions and 0 deletions

5
app.css Normal file
View File

@ -0,0 +1,5 @@
/**
* Comunic WebApp custom stylesheet
*
* @author Comunic authors
*/

View File

@ -10,6 +10,7 @@ const {Menu, Tray} = require('electron');
const Config = require("../Config");
const TrayMenu = require("./TrayMenu");
const ApplicationMenu = require("./ApplicationMenu");
const fs = require("fs");
let mainWindow;
@ -58,5 +59,21 @@ exports.show = function(){
mainWindow.webContents.on('did-finish-load', function() {
page_finished_loading = true;
//Inject CSS
fs.readFile("./app.css", (err, data) => {
//Check for errors
if(err){
console.error("Error while loading ./app.css: " + err);
return;
}
let style = data.toString();
mainWindow.webContents.executeJavaScript("let style = document.createElement('style');" +
"style.innerHTML = decodeURIComponent(\""+encodeURIComponent(style)+"\");" +
"document.head.appendChild(style);");
});
});
}