Skip to content

Commit 64ac111

Browse files
committed
Rename UI_MODE to THEME
1 parent e9f170a commit 64ac111

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

docs/releases.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ Released June 28, 2023
77

88
With this release, the ntfy web app now contains a **[progressive web app](https://docs.ntfy.sh/subscribe/pwa/) (PWA)
99
with Web Push support**, which means you'll be able to **install the ntfy web app on your desktop or phone** similar
10-
to a native app (__even on iOS!__ 🥳), and get basic push notification support (without any battery drain).
10+
to a native app (__even on iOS!__ 🥳). Installing the PWA gives ntfy web its own launcher, a standalone window,
11+
push notifications, and an app badge with the unread notification count.
1112

12-
Installing the PWA gives ntfy web its own launcher (e.g. shortcut on Windows, app on macOS, launcher shortcut on Linux,
13-
home screen icon on iOS, and launcher icon on Android), a standalone window, push notifications, and an app badge with
14-
the unread notification count.
13+
On top of that, this release also brings **dark mode** 🧛🌙 to the web app.
14+
15+
🙏 A huge thanks for this release goes to [@nimbleghost](https://github.com/nimbleghost), for basically implementing the
16+
Web Push / PWA and dark mode feature by himself. I'm really grateful for your contributions.
17+
18+
❤️ If you like ntfy, **please consider sponsoring us** via [GitHub Sponsors](https://github.com/sponsors/binwiederhier)
19+
and [Liberapay](https://en.liberapay.com/ntfy/), or buying a [paid plan via the web app](https://ntfy.sh/app) (20% off
20+
if you use promo code `MYTOPIC`). ntfy will always remain open source.
1521

1622
**Features:**
1723

1824
* The web app now supports Web Push, and is installable as a [progressive web app (PWA)](https://docs.ntfy.sh/subscribe/pwa/) on Chrome, Edge, Android, and iOS ([#751](https://github.com/binwiederhier/ntfy/pull/751), thanks to [@nimbleghost](https://github.com/nimbleghost))
25+
* Support for dark mode in the web app ([#206](https://github.com/binwiederhier/ntfy/issues/206), thanks to [@nimbleghost](https://github.com/nimbleghost))
1926

2027
**Bug fixes:**
2128

web/public/static/langs/en.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,6 @@
338338
"prefs_notifications_web_push_disabled_description": "Notification are received when the web app is running (via WebSocket)",
339339
"prefs_notifications_web_push_enabled": "Enabled for {{server}}",
340340
"prefs_notifications_web_push_disabled": "Disabled",
341-
"prefs_ui_mode_title": "UI Mode",
342-
"prefs_ui_mode_system": "System (default)",
343-
"prefs_ui_mode_dark": "Dark",
344-
"prefs_ui_mode_light": "Light",
345341
"prefs_users_title": "Manage users",
346342
"prefs_users_description": "Add/remove users for your protected topics here. Please note that username and password are stored in the browser's local storage.",
347343
"prefs_users_description_no_sync": "Users and passwords are not synchronized to your account.",
@@ -359,6 +355,10 @@
359355
"prefs_users_dialog_password_label": "Password",
360356
"prefs_appearance_title": "Appearance",
361357
"prefs_appearance_language_title": "Language",
358+
"prefs_appearance_theme_title": "Theme",
359+
"prefs_appearance_theme_system": "System (default)",
360+
"prefs_appearance_theme_dark": "Dark mode",
361+
"prefs_appearance_theme_light": "Light mode",
362362
"prefs_reservations_title": "Reserved topics",
363363
"prefs_reservations_description": "You can reserve topic names for personal use here. Reserving a topic gives you ownership over the topic, and allows you to define access permissions for other users over the topic.",
364364
"prefs_reservations_limit_reached": "You reached your reserved topics limit.",

web/src/app/Prefs.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import db from "./db";
22

3-
export const UI_MODE = {
3+
export const THEME = {
44
DARK: "dark",
55
LIGHT: "light",
66
SYSTEM: "system",
@@ -47,13 +47,13 @@ class Prefs {
4747
await this.db.prefs.put({ key: "webPushEnabled", value: enabled });
4848
}
4949

50-
async uiMode() {
51-
const uiMode = await this.db.prefs.get("uiMode");
52-
return uiMode?.value ?? UI_MODE.SYSTEM;
50+
async theme() {
51+
const theme = await this.db.prefs.get("theme");
52+
return theme?.value ?? THEME.SYSTEM;
5353
}
5454

55-
async setUIMode(mode) {
56-
await this.db.prefs.put({ key: "uiMode", value: mode });
55+
async setTheme(mode) {
56+
await this.db.prefs.put({ key: "theme", value: mode });
5757
}
5858
}
5959

web/src/components/App.jsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ import Login from "./Login";
2222
import Signup from "./Signup";
2323
import Account from "./Account";
2424
import "../app/i18n"; // Translations!
25-
import prefs, { UI_MODE } from "../app/Prefs";
25+
import prefs, { THEME } from "../app/Prefs";
2626

2727
export const AccountContext = createContext(null);
2828

29-
const darkModeEnabled = (prefersDarkMode, uiModePreference) => {
30-
switch (uiModePreference) {
31-
case UI_MODE.DARK:
29+
const darkModeEnabled = (prefersDarkMode, themePreference) => {
30+
switch (themePreference) {
31+
case THEME.DARK:
3232
return true;
3333

34-
case UI_MODE.LIGHT:
34+
case THEME.LIGHT:
3535
return false;
3636

37-
case UI_MODE.SYSTEM:
37+
case THEME.SYSTEM:
3838
default:
3939
return prefersDarkMode;
4040
}
@@ -43,20 +43,17 @@ const darkModeEnabled = (prefersDarkMode, uiModePreference) => {
4343
const App = () => {
4444
const [account, setAccount] = useState(null);
4545
const accountMemo = useMemo(() => ({ account, setAccount }), [account, setAccount]);
46-
4746
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
48-
49-
const uiModePreference = useLiveQuery(() => prefs.uiMode());
50-
47+
const themePreference = useLiveQuery(() => prefs.theme());
5148
const theme = React.useMemo(
5249
() =>
5350
createTheme({
5451
...themeOptions,
5552
palette: {
56-
...(darkModeEnabled(prefersDarkMode, uiModePreference) ? darkPalette : lightPalette),
53+
...(darkModeEnabled(prefersDarkMode, themePreference) ? darkPalette : lightPalette),
5754
},
5855
}),
59-
[prefersDarkMode, uiModePreference]
56+
[prefersDarkMode, themePreference]
6057
);
6158

6259
return (

web/src/components/Preferences.jsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import accountApi, { Permission, Role } from "../app/AccountApi";
4343
import { Pref, PrefGroup } from "./Pref";
4444
import { AccountContext } from "./App";
4545
import { Paragraph } from "./styles";
46-
import prefs, { UI_MODE } from "../app/Prefs";
46+
import prefs, { THEME } from "../app/Prefs";
4747
import { PermissionDenyAll, PermissionRead, PermissionReadWrite, PermissionWrite } from "./ReserveIcons";
4848
import { ReserveAddDialog, ReserveDeleteDialog, ReserveEditDialog } from "./ReserveDialogs";
4949
import { UnauthorizedError } from "../app/errors";
@@ -86,7 +86,6 @@ const Notifications = () => {
8686
{t("prefs_notifications_title")}
8787
</Typography>
8888
<PrefGroup>
89-
<UIMode />
9089
<Sound />
9190
<MinPriority />
9291
<DeleteAfter />
@@ -238,21 +237,21 @@ const DeleteAfter = () => {
238237
);
239238
};
240239

241-
const UIMode = () => {
240+
const Theme = () => {
242241
const { t } = useTranslation();
243-
const labelId = "prefUIMode";
244-
const enabled = useLiveQuery(async () => prefs.uiMode());
242+
const labelId = "prefTheme";
243+
const enabled = useLiveQuery(async () => prefs.theme());
245244
const handleChange = async (ev) => {
246-
await prefs.setUIMode(ev.target.value);
245+
await prefs.setTheme(ev.target.value);
247246
};
248247

249248
return (
250-
<Pref labelId={labelId} title={t("prefs_ui_mode_title")}>
249+
<Pref labelId={labelId} title={t("prefs_appearance_theme_title")}>
251250
<FormControl fullWidth variant="standard" sx={{ m: 1 }}>
252251
<Select value={enabled ?? false} onChange={handleChange} aria-labelledby={labelId}>
253-
<MenuItem value={UI_MODE.SYSTEM}>{t("prefs_ui_mode_system")}</MenuItem>
254-
<MenuItem value={UI_MODE.DARK}>{t("prefs_ui_mode_dark")}</MenuItem>
255-
<MenuItem value={UI_MODE.LIGHT}>{t("prefs_ui_mode_light")}</MenuItem>
252+
<MenuItem value={THEME.SYSTEM}>{t("prefs_appearance_theme_system")}</MenuItem>
253+
<MenuItem value={THEME.DARK}>{t("prefs_appearance_theme_dark")}</MenuItem>
254+
<MenuItem value={THEME.LIGHT}>{t("prefs_appearance_theme_light")}</MenuItem>
256255
</Select>
257256
</FormControl>
258257
</Pref>
@@ -511,6 +510,7 @@ const Appearance = () => {
511510
{t("prefs_appearance_title")}
512511
</Typography>
513512
<PrefGroup>
513+
<Theme />
514514
<Language />
515515
</PrefGroup>
516516
</Card>

0 commit comments

Comments
 (0)