sozsoft-platform/ui/src/utils/hooks/usePWA.ts
2026-08-14 14:32:31 +03:00

26 lines
736 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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