luci-theme-bootstrap: add explicit dark/light mode selection
Register two further "virtual" themes called BootstrapDark and BootstrapLight which force dark and light mode respectively. The actual Bootstrap theme itself will continue to auto-select dark mode preference based on OS/Browser preference settings. Fixes: #5492 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
cd6ad0a242
commit
ed86f03a9f
7 changed files with 55 additions and 19 deletions
1
themes/luci-theme-bootstrap/htdocs/luci-static/bootstrap-dark
Symbolic link
1
themes/luci-theme-bootstrap/htdocs/luci-static/bootstrap-dark
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
bootstrap
|
1
themes/luci-theme-bootstrap/htdocs/luci-static/bootstrap-light
Symbolic link
1
themes/luci-theme-bootstrap/htdocs/luci-static/bootstrap-light
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
bootstrap
|
|
@ -70,18 +70,16 @@
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
:root[data-darkmode="true"] {
|
||||||
:root {
|
--background-color-delta-l-sign: 1;
|
||||||
--background-color-delta-l-sign: 1;
|
--background-color-high-h: 0;
|
||||||
--background-color-high-h: 0;
|
--background-color-high-s: 0%;
|
||||||
--background-color-high-s: 0%;
|
--background-color-high-l: calc(34 / 255 * 100%);
|
||||||
--background-color-high-l: calc(34 / 255 * 100%);
|
--text-color-delta-l-sign: -1;
|
||||||
--text-color-delta-l-sign: -1;
|
--text-color-highest-h: 0;
|
||||||
--text-color-highest-h: 0;
|
--text-color-highest-s: 0%;
|
||||||
--text-color-highest-s: 0%;
|
--text-color-highest-l: 100%;
|
||||||
--text-color-highest-l: 100%;
|
--border-color-delta-l-sign: 1;
|
||||||
--border-color-delta-l-sign: 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset.less
|
/* Reset.less
|
||||||
|
|
1
themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap-dark
Symbolic link
1
themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap-dark
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
bootstrap
|
1
themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap-light
Symbolic link
1
themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap-light
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
bootstrap
|
|
@ -15,14 +15,32 @@
|
||||||
|
|
||||||
local node = disp.context.dispatched
|
local node = disp.context.dispatched
|
||||||
|
|
||||||
|
local darkpref
|
||||||
|
|
||||||
|
if theme == "bootstrap-dark" then
|
||||||
|
darkpref = "true"
|
||||||
|
elseif theme == "bootstrap-light" then
|
||||||
|
darkpref = "false"
|
||||||
|
end
|
||||||
|
|
||||||
-- send as HTML5
|
-- send as HTML5
|
||||||
http.prepare_content("text/html")
|
http.prepare_content("text/html")
|
||||||
-%>
|
-%>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="<%=luci.i18n.context.lang%>">
|
<html lang="<%=luci.i18n.context.lang%>"<%= ifattr(darkpref ~= nil, "data-darkmode", darkpref) %>>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
|
<title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
|
||||||
|
<% if darkpref == nil then %>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'),
|
||||||
|
rootElement = document.querySelector(':root'),
|
||||||
|
setDarkMode = function(match) { rootElement.setAttribute('data-darkmode', match.matches) };
|
||||||
|
|
||||||
|
mediaQuery.addEventListener('change', setDarkMode);
|
||||||
|
setDarkMode(mediaQuery);
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
<meta name="viewport" content="initial-scale=1.0">
|
<meta name="viewport" content="initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="<%=media%>/cascade.css">
|
<link rel="stylesheet" href="<%=media%>/cascade.css">
|
||||||
<link rel="stylesheet" media="only screen and (max-device-width: 854px)" href="<%=media%>/mobile.css" type="text/css" />
|
<link rel="stylesheet" media="only screen and (max-device-width: 854px)" href="<%=media%>/mobile.css" type="text/css" />
|
||||||
|
|
|
@ -1,12 +1,28 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
changed=0
|
||||||
|
|
||||||
|
set_opt() {
|
||||||
|
local key=$1
|
||||||
|
local val=$2
|
||||||
|
|
||||||
|
if ! uci -q get "luci.themes.$key" 2>/dev/null; then
|
||||||
|
uci set "luci.themes.$key=$val"
|
||||||
|
changed=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
set_opt Bootstrap /luci-static/bootstrap
|
||||||
|
set_opt BootstrapDark /luci-static/bootstrap-dark
|
||||||
|
set_opt BootstrapLight /luci-static/bootstrap-light
|
||||||
|
|
||||||
if [ "$PKG_UPGRADE" != 1 ]; then
|
if [ "$PKG_UPGRADE" != 1 ]; then
|
||||||
uci get luci.themes.Bootstrap >/dev/null 2>&1 || \
|
uci set luci.main.mediaurlbase=/luci-static/bootstrap
|
||||||
uci batch <<-EOF
|
changed=1
|
||||||
set luci.themes.Bootstrap=/luci-static/bootstrap
|
fi
|
||||||
set luci.main.mediaurlbase=/luci-static/bootstrap
|
|
||||||
commit luci
|
if [ $changed = 1 ]; then
|
||||||
EOF
|
uci commit luci
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue