sozsoft-platform/ui/src/utils/hooks/usePWA.ts

27 lines
736 B
TypeScript
Raw Normal View History

2026-08-14 11:32:31 +00:00
import { useEffect, useState } from 'react'
2026-02-24 20:44:16 +00:00
export function usePWA(): boolean {
2026-08-14 11:32:31 +00:00
const [isPWA, setIsPWA] = useState(false)
2026-02-24 20:44:16 +00:00
useEffect(() => {
const checkPWA = () => {
2026-08-14 11:32:31 +00:00
const isStandalone =
window.matchMedia('(display-mode: standalone)').matches ||
(window.navigator as any).standalone
setIsPWA(isStandalone)
}
2026-02-24 20:44:16 +00:00
2026-08-14 11:32:31 +00:00
checkPWA() // İlk kontrolü yap
2026-02-24 20:44:16 +00:00
// display-mode değiştiğinde güncellenmesi için event listener ekle
2026-08-14 11:32:31 +00:00
window.matchMedia('(display-mode: standalone)').addEventListener('change', checkPWA)
2026-02-24 20:44:16 +00:00
return () => {
// Event listener'ı temizle
2026-08-14 11:32:31 +00:00
window.matchMedia('(display-mode: standalone)').removeEventListener('change', checkPWA)
}
}, [])
2026-02-24 20:44:16 +00:00
2026-08-14 11:32:31 +00:00
return isPWA
2026-02-24 20:44:16 +00:00
}