diff --git a/CHANGELOG.md b/CHANGELOG.md index e6d1948c..f08ebc39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,9 @@ - PostgreSQL, CockroachDB: Creating partitioned tables (bug #1031) - PostgreSQL: Move partitioned tables from table list to parent table - PostgreSQL: Support calling functions returning table (bug #1040) -- Designs: adminer.css with 'prefers-color-scheme: dark' don't disable dark mode +- Designs: adminer.css with 'prefers-color-scheme: dark' doesn't disable dark mode - Plugins: Method bodyClass() to add <body class> +- Plugins: Allow setting dark mode in css() - Hindi translation ## Adminer 5.2.1 (released 2025-04-11) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 1000711e..eb0338ab 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -114,14 +114,18 @@ class Adminer { } /** Get URLs of the CSS files - * @return list + * @return string[] key is URL, value is either 'light' (supports only light color scheme), 'dark' or '' (both) */ function css(): array { $return = array(); foreach (array("", "-dark") as $mode) { $filename = "adminer$mode.css"; if (file_exists($filename)) { - $return[] = "$filename?v=" . crc32(file_get_contents($filename)); + $file = file_get_contents($filename); + $return["$filename?v=" . crc32($file)] = ($mode + ? "dark" + : (preg_match('~prefers-color-scheme:\s*dark~', $file) ? '' : 'light') + ); } } return $return; diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index d074ca21..9f16c7c2 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -29,20 +29,11 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s css(); - $has_light = false; - $has_dark = false; - foreach ($css as $url) { - if (strpos($url, "adminer.css") !== false) { - $has_light = true; - $filename = preg_replace('~\?.*~', '', $url); - if (!preg_match('~//~', $url) && is_readable($filename) && preg_match('~prefers-color-scheme:\s*dark~', file_get_contents($filename))) { - $has_dark = true; - } - } - if (strpos($url, "adminer-dark.css") !== false) { - $has_dark = true; - } + if (is_int(key($css))) { // legacy return value + $css = array_fill_keys($css, 'light'); } + $has_light = in_array('light', $css) || in_array('', $css); + $has_dark = in_array('dark', $css) || in_array('', $css); $dark = ($has_light ? ($has_dark ? null : false) // both styles - autoswitching, only adminer.css - light : ($has_dark ?: null) // only adminer-dark.css - dark, neither - autoswitching @@ -60,8 +51,8 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s echo "\n"; echo "\n"; } - foreach ($css as $val) { - echo "\n"; + foreach ($css as $url => $mode) { + echo "\n"; } echo "\nbodyClass(); diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 7aa478af..c66e5cea 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -79,7 +79,11 @@ class Adminer { foreach (array("", "-dark") as $mode) { $filename = "adminer$mode.css"; if (file_exists($filename)) { - $return[] = "$filename?v=" . crc32(file_get_contents($filename)); + $file = file_get_contents($filename); + $return["$filename?v=" . crc32($file)] = ($mode + ? "dark" + : (preg_match('~prefers-color-scheme:\s*dark~', $file) ? '' : 'light') + ); } } return $return; diff --git a/plugins/designs.php b/plugins/designs.php index 8b93ad3a..318db8a9 100644 --- a/plugins/designs.php +++ b/plugins/designs.php @@ -27,7 +27,7 @@ class AdminerDesigns extends Adminer\Plugin { function css() { $return = array(); if (array_key_exists($_SESSION["design"], $this->designs)) { - $return[] = $_SESSION["design"]; + $return[$_SESSION["design"]] = (preg_match('~-dark~', $_SESSION["design"]) ? "dark" : "light"); } return $return; }