fix: guide users through blocked notification permissions

This commit is contained in:
2026-09-06 14:41:24 +03:00
parent df0626a71f
commit 38227862c0
3 changed files with 47 additions and 10 deletions
+38 -8
View File
@@ -36,7 +36,17 @@ const PwaPanel = () => {
return () => { window.removeEventListener('online', changed); window.removeEventListener('offline', changed); };
}, []);
const [installed, setInstalled] = useState(false);
const [permission, setPermission] = useState(typeof Notification !== 'undefined' ? Notification.permission : 'unsupported');
const readPermission = () => typeof Notification !== 'undefined' ? Notification.permission : 'unsupported';
const [permission, setPermission] = useState(readPermission);
const [permissionBusy,setPermissionBusy]=useState(false),[permissionError,setPermissionError]=useState(null);
const permissionLock=useRef(false);
const refreshPermission=()=>setPermission(readPermission());
useEffect(()=>{
const refresh=()=>{if(document.visibilityState==='visible')refreshPermission();};
window.addEventListener('focus',refresh);
document.addEventListener('visibilitychange',refresh);
return()=>{window.removeEventListener('focus',refresh);document.removeEventListener('visibilitychange',refresh);};
},[]);
// E-posta (Resend) durumu + test gönderimi
const [emailCfg, setEmailCfg] = useState(null); // null=bilinmiyor, true/false
@@ -64,12 +74,23 @@ const PwaPanel = () => {
};
const handleEnablePush = async () => {
const p = await requestPushPermission();
setPermission(p);
if (p === 'granted') {
await saveReminderSettings((s) => ({ ...s, pushEnabled: true }));
if(permissionLock.current || reminderSaving)return;
const current=readPermission();setPermission(current);
if(current==='denied'||current==='unsupported')return;
permissionLock.current=true;setPermissionBusy(true);setPermissionError(null);
try {
const p = await requestPushPermission();
if(!alive.current)return;
setPermission(p);
if(p==='granted')await saveReminderSettings(s=>({...s,pushEnabled:true}));
} catch(error) {
if(alive.current){refreshPermission();setPermissionError(error.message || 'Bildirim izni alınamadı.');}
} finally {
permissionLock.current=false;
if(alive.current)setPermissionBusy(false);
}
};
const setQuiet = (patch) => saveReminderSettings((s) => ({ ...s, ...patch }));
// Gerçek PWA kurulumu: tarayıcı beforeinstallprompt verirse yerel diyalog;
@@ -168,10 +189,17 @@ const PwaPanel = () => {
Bu uygulama açıkken alınan uyarıları tarayıcı bildirimi olarak gösterebilirsiniz. Kapalı uygulamaya arka plan push teslimi sağlanmaz.
</p>
{permission !== 'granted' ? (
<button onClick={handleEnablePush} disabled={reminderSaving || permission === 'unsupported'}
{permission === 'denied' ? (
<div className="space-y-2 text-xs text-slate-700">
<p>Bu site için bildirimler tarayıcı tarafından engellenmiş. Adres çubuğundaki site bilgileri veya tarayıcının site ayarlarından bildirim iznini değiştirin, ardından buraya dönün.</p>
<button onClick={refreshPermission} className="border rounded px-3 py-2">Bildirim iznini yeniden kontrol et</button>
</div>
) : permission === 'unsupported' ? (
<p className="text-xs text-slate-700">Bu tarayıcıda bildirim özelliği kullanılamıyor. Uygulama içindeki bildirim listesini kullanabilirsiniz.</p>
) : permission !== 'granted' ? (
<button onClick={handleEnablePush} disabled={reminderSaving || permissionBusy}
className="w-full bg-amber-500 hover:bg-amber-400 disabled:opacity-40 text-white font-bold text-xs py-2.5 rounded-xl">
Bildirimlere İzin Ver
{permissionBusy?'İzin yanıtı bekleniyor…':'Bildirimlere İzin Ver'}
</button>
) : (
<button onClick={() => notify('Test bildirimi', isQuietNow() || !reminderSettings.pushEnabled ? 'Tarayıcı bildirimi kapalı veya sessiz saatte — listeye eklendi.' : 'Tarayıcı bildirimi gösterim denemesi.')}
@@ -180,11 +208,13 @@ const PwaPanel = () => {
</button>
)}
{permissionError&&<p role="alert" className="text-xs text-red-700">{permissionError}</p>}
{reminderError&&<p role="alert" className="text-xs text-red-700">{reminderError}</p>}
{reminderSaving&&<p role="status" className="text-xs">Bildirim ayarları kaydediliyor…</p>}
<label className="flex justify-between text-xs font-bold">Tarayıcı bildirimlerini göster
<input type="checkbox" checked={reminderSettings.pushEnabled} disabled={reminderSaving} onChange={e=>setQuiet({pushEnabled:e.target.checked})}/>
</label>
{permission!=='granted'&&<p className="text-xs text-slate-600">Bildirim tercihiniz kaydedilir; tarayıcı izni verilmeden masaüstü bildirimi gösterilemez.</p>}
{/* Sessiz saatler — gerçek */}
<div className="pt-2 border-t border-slate-100 space-y-2">
<p className="text-xs text-slate-500">Saatler bu cihazın yerel saatine göredir. Başlangıç ve bitiş aynıysa sessiz süre uygulanmaz.</p>
+2 -2
View File
@@ -592,8 +592,8 @@ export const AppProvider = ({ children }) => {
};
const requestPushPermission = async () => {
if (!('Notification' in window)) return 'unsupported';
if (Notification.permission === 'granted') return 'granted';
try { return await Notification.requestPermission(); } catch { return 'denied'; }
if (Notification.permission !== 'default') return Notification.permission;
return await Notification.requestPermission();
};
const refreshNotifications=async()=>{
const session=getToken(),version=++notificationVersion.current;