Skip to content

Commit a5bfc3e

Browse files
committed
Added option to set default theme (light/dark/auto) GH-241
1 parent 91308b3 commit a5bfc3e

34 files changed

+30
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,4 @@ See https://github.com/Daveiano/weewx-wdc/compare/v3.3.0...580071ca175a03fe4924b
764764
- Updated windGust display in forecast table GH-240
765765
- Updated sorting of min/max graphs in the `temp_min_max_avg` graph GH-247
766766
- Added new property for charts: `legendPosition` - Change legend position GH-228
767+
- Added option to set default theme (light/dark/auto) GH-241

skins/weewx-wdc/includes/html-head.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
"Format_is": "$gettext('Format is')",
8585
},
8686
locale: "$get_locale()",
87-
time: $datetime.datetime.now().timestamp()
87+
time: $datetime.datetime.now().timestamp(),
88+
defaultTheme: '$DisplayOptions.get("default_theme", "auto")'
8889
};
8990
</script>
9091

skins/weewx-wdc/includes/ui-shell.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@
383383
</script>
384384

385385
<script>
386+
// Default theme.
387+
const defaultTheme = window.weewxWdcConfig.defaultTheme;
388+
389+
if (!("weewx.weewx_wdc.color-theme" in localStorage) && defaultTheme !== "auto") {
390+
localStorage.setItem("weewx.weewx_wdc.color-theme", defaultTheme);
391+
}
392+
386393
var themeToggleDarkIcon = document.querySelectorAll(
387394
'[data-id="theme-toggle-dark-icon"]'
388395
);

skins/weewx-wdc/skin.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ SKIN_VERSION = 3.5.0-alpha1
117117
# 'alternative' or 'classic'.
118118
layout = 'alternative'
119119

120+
# 'auto', 'light' or 'dark'.
121+
default_theme = 'auto'
122+
120123
# Date/Time localization for charts. Available locales: de-DE, en-US, en-GB, it-IT, nl-NL.
121124
# If not set, the value from weewx.conf (reports section) will be used. If lang = en, then en-US will be used (sorry GB!).
122125
#date_time_locale = en-US

test/e2e-tests/basic/basic.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ test.describe("Basic pages display", () => {
103103
test("Dark mode", async ({ page }) => {
104104
await page.goto("artifacts-alternative-weewx-html/public_html/index.html");
105105

106+
await expect(page).toHaveScreenshot({ fullPage: true });
107+
106108
// Switch to dark theme.
107109
await page.locator("bx-header #header-global bx-btn").click();
108110
await expect(page).toHaveScreenshot({ fullPage: true });
@@ -128,3 +130,15 @@ test("Dark mode", async ({ page }) => {
128130
).toBeVisible();
129131
await expect(page).toHaveScreenshot({ fullPage: true });
130132
});
133+
134+
test("Default theme dark", async ({ page }) => {
135+
await page.goto("artifacts-mqtt-weewx-html/public_html/index.html");
136+
await expect(page.locator("html")).toHaveClass(/dark/);
137+
await expect(page).toHaveScreenshot({ fullPage: true });
138+
});
139+
140+
test("Default theme light", async ({ page }) => {
141+
await page.goto("artifacts-sensor-status-weewx-html/public_html/index.html");
142+
await expect(page.locator("html")).not.toHaveClass(/dark/);
143+
await expect(page).toHaveScreenshot({ fullPage: true });
144+
});
-3.17 KB
Loading
16.1 KB
Loading

0 commit comments

Comments
 (0)