PWA-Benachrichtigungen auch ohne Push-Unterstützung anzeigen

This commit is contained in:
torsten 2026-11-08 20:23:39 +01:00
parent 972fec83ab
commit cb42e5b81a

View file

@ -86,8 +86,8 @@
<?= csrf_field() ?>
</form>
<?php if ($isOwnProfile && $pushPublicKey !== null): ?>
<div class="card text-dark mt-4 text-left" id="push-settings" hidden
<?php if ($isOwnProfile && $pushPublicKey !== null && !is_desktop()): ?>
<div class="card text-dark mt-4 text-left" id="push-settings"
data-vapid-key="<?= e($pushPublicKey) ?>"
data-push-enabled="<?= $pushEnabled ? '1' : '0' ?>">
<div class="card-body">
@ -124,19 +124,9 @@
}
var vapidKey = group.getAttribute('data-vapid-key') || '';
var ua = navigator.userAgent || '';
var isMobile = /Android|iPhone|iPad|iPod|Mobile|Windows Phone/i.test(ua)
|| (/Macintosh/i.test(ua) && navigator.maxTouchPoints > 1);
var supported = 'serviceWorker' in navigator && 'PushManager' in window && 'Notification' in window;
var isStandalone = window.matchMedia('(display-mode: standalone)').matches
|| window.navigator.standalone === true;
var supported = 'serviceWorker' in navigator && 'PushManager' in window && 'Notification' in window;
// Nur auf Smartphones (bzw. in der installierten App) anzeigen.
if ((!isMobile && !isStandalone) || !supported || !vapidKey) {
return;
}
group.hidden = false;
function setHint(text, isError) {
hint.textContent = text || '';
@ -147,6 +137,25 @@
testButton.hidden = !box.checked;
}
if (!vapidKey) {
box.disabled = true;
testButton.hidden = true;
setHint('Benachrichtigungen sind auf diesem Server noch nicht eingerichtet.', true);
return;
}
if (!supported) {
box.disabled = true;
testButton.hidden = true;
setHint(
isStandalone
? 'Dieser Browser unterstützt keine Push-Benachrichtigungen.'
: 'Push-Benachrichtigungen brauchen einen unterstützten Browser. Auf dem iPhone: Seite in Safari öffnen, „Teilen“ → „Zum Home-Bildschirm“ wählen und die App vom Startbildschirm aus öffnen.',
true
);
return;
}
function keyToBytes(base64url) {
var padding = new Array((4 - (base64url.length % 4)) % 4 + 1).join('=');
var base64 = (base64url + padding).replace(/-/g, '+').replace(/_/g, '/');