mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-01 14:31:51 +02:00
Hide web push toggles if disabled on server
This commit is contained in:
parent
0c25425346
commit
7aa3d8f59b
2 changed files with 6 additions and 3 deletions
web/src
|
@ -115,7 +115,7 @@ class Notifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
pushSupported() {
|
pushSupported() {
|
||||||
return "serviceWorker" in navigator && "PushManager" in window;
|
return config.enable_web_push && "serviceWorker" in navigator && "PushManager" in window;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -103,6 +103,7 @@ const SubscribeDialog = (props) => {
|
||||||
const browserNotificationsSupported = notifier.supported();
|
const browserNotificationsSupported = notifier.supported();
|
||||||
const pushNotificationsSupported = notifier.pushSupported();
|
const pushNotificationsSupported = notifier.pushSupported();
|
||||||
const iosInstallRequired = notifier.iosSupportedButInstallRequired();
|
const iosInstallRequired = notifier.iosSupportedButInstallRequired();
|
||||||
|
const pushPossible = pushNotificationsSupported && iosInstallRequired;
|
||||||
|
|
||||||
const getNotificationTypeFromToggles = (browserNotificationsEnabled, backgroundNotificationsEnabled) => {
|
const getNotificationTypeFromToggles = (browserNotificationsEnabled, backgroundNotificationsEnabled) => {
|
||||||
if (backgroundNotificationsEnabled) {
|
if (backgroundNotificationsEnabled) {
|
||||||
|
@ -138,12 +139,14 @@ const SubscribePage = (props) => {
|
||||||
const [notificationsExplicitlyDenied, setNotificationsExplicitlyDenied] = useState(notifier.denied());
|
const [notificationsExplicitlyDenied, setNotificationsExplicitlyDenied] = useState(notifier.denied());
|
||||||
// default to on if notifications are already granted
|
// default to on if notifications are already granted
|
||||||
const [browserNotificationsEnabled, setBrowserNotificationsEnabled] = useState(notifier.granted());
|
const [browserNotificationsEnabled, setBrowserNotificationsEnabled] = useState(notifier.granted());
|
||||||
const [backgroundNotificationsEnabled, setBackgroundNotificationsEnabled] = useState(props.webPushDefaultEnabled === "enabled");
|
const [backgroundNotificationsEnabled, setBackgroundNotificationsEnabled] = useState(
|
||||||
|
pushPossible && props.webPushDefaultEnabled === "enabled"
|
||||||
|
);
|
||||||
|
|
||||||
const handleBrowserNotificationsChanged = async (e) => {
|
const handleBrowserNotificationsChanged = async (e) => {
|
||||||
if (e.target.checked && (await notifier.maybeRequestPermission())) {
|
if (e.target.checked && (await notifier.maybeRequestPermission())) {
|
||||||
setBrowserNotificationsEnabled(true);
|
setBrowserNotificationsEnabled(true);
|
||||||
if (props.webPushDefaultEnabled === "enabled") {
|
if (pushPossible && props.webPushDefaultEnabled === "enabled") {
|
||||||
setBackgroundNotificationsEnabled(true);
|
setBackgroundNotificationsEnabled(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue