doxygen-awesome-css icon indicating copy to clipboard operation
doxygen-awesome-css copied to clipboard

Configure dark mode be the default on page load

Open jdillard opened this issue 2 years ago • 3 comments

As a fan of dark mode, I thought it would be nice to have a configuration option to set dark mode on initial page load. I started looking into how to implement it, but thought I would open a "feature request" just in case.

jdillard avatar Oct 05 '21 17:10 jdillard

Would you like to always enable dark mode, without providing the toggle button to the user? Or should dark be the default but the user should be allowed to disable it?

jothepro avatar Oct 08 '21 17:10 jothepro

The latter. I was thinking something like a config variable that added class="dark-mode" or class="light-mode" to the template and having the javascript check for the class, but I just realized that would require making another manual edit to the templates generated by Doxygen.

jdillard avatar Oct 08 '21 18:10 jdillard

The script in doxygen-awesome-darkmode-toggle.js reads a value from the local storage at page load to determine if it should enable dark mode. You could write a custom script that sets the key prefers-dark-mode-in-light-mode on the users first page visit, remembering if you did so in another key:

if(localStorage.getItem("kilroy-was-here") === null) {
  localStorage.setItem("kilroy-was-here", true)
  localStorage.setItem("prefers-dark-mode-in-light-mode", true)
}

Disclaimer: This is not a decent solution but more of a workaround for your requirement. It does also require the template to be edited (for adding the script). I've not tested if this works, but in my head it does :wink:)

jothepro avatar Oct 08 '21 18:10 jothepro