sozsoft-platform/ui/src/utils/hooks/usePWA.ts
Sedat Öztürk 429227df1d Initial
2026-02-24 23:44:16 +03:00

24 lines
731 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;
}