From 0ec6cf80db681ea7fbc7f32a29d87d7d4d223154 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 11 Feb 2019 20:12:17 +0100 Subject: [PATCH] Ready to inject CSS in app --- app.css | 5 +++++ modules/MainWindow.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 app.css diff --git a/app.css b/app.css new file mode 100644 index 0000000..cf62660 --- /dev/null +++ b/app.css @@ -0,0 +1,5 @@ +/** + * Comunic WebApp custom stylesheet + * + * @author Comunic authors + */ \ No newline at end of file diff --git a/modules/MainWindow.js b/modules/MainWindow.js index da11d2a..e5ac127 100644 --- a/modules/MainWindow.js +++ b/modules/MainWindow.js @@ -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);"); + + }); }); } \ No newline at end of file