I read on the electron's guide to implement dark mode to your app, but it only works when the user clicks a button to manually change it to dark mode. What I want to do is, when the system is in 'dark mode', I wanted the CSS tag to change. For instance, when a user has Dark Mode turned on in the system, it'll change the css background color to black.
here's the HTML code:
<nav class="navbar navbar-light bg-light">
Here's the javascript in the renderer.js file I used from this site with jQuery. I also had to use the console.log module to test to make sure the trigger works.
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', event => {
if (event.matches) {
//dark mode
$("nav.navbar-light bg-light").replaceWith( "navbar-light bg-dark" );
console.log("This is Dark Mode");
} else {
//light mode
$("nav.navbar-light bg-light").replaceWith( "navbar-light bg-light" );
console.log("This is Light Mode");
}
})
I tried those, and nothing showed up on my console on launch. I know there has to be a different window.NAMEOFTHING in Electron/Node.js. I guess there's another npm I should try?