Formatting
parent
0c496ca223
commit
12df164245
|
@ -78,7 +78,6 @@ const Preferences = () => (
|
||||||
|
|
||||||
const Notifications = () => {
|
const Notifications = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const isLaunchedPWA = useIsLaunchedPWA();
|
const isLaunchedPWA = useIsLaunchedPWA();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -136,6 +136,8 @@ export const useAutoSubscribe = (subscriptions, selected) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const webPushBroadcastChannel = new BroadcastChannel("web-push-broadcast");
|
const webPushBroadcastChannel = new BroadcastChannel("web-push-broadcast");
|
||||||
|
const matchMedia = window.matchMedia("(display-mode: standalone)");
|
||||||
|
const isIOSStandalone = window.navigator.standalone === true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the Web Push subscriptions when the list of topics changes,
|
* Updates the Web Push subscriptions when the list of topics changes,
|
||||||
|
@ -212,35 +214,27 @@ export const useWebPushTopics = () => {
|
||||||
return topics;
|
return topics;
|
||||||
};
|
};
|
||||||
|
|
||||||
const matchMedia = window.matchMedia("(display-mode: standalone)");
|
|
||||||
|
|
||||||
const isIOSStandAlone = window.navigator.standalone === true;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Watches the "display-mode" to detect if the app is running as a standalone app (PWA),
|
* Watches the "display-mode" to detect if the app is running as a standalone app (PWA).
|
||||||
*/
|
*/
|
||||||
export const useIsLaunchedPWA = () => {
|
export const useIsLaunchedPWA = () => {
|
||||||
const [isStandalone, setIsStandalone] = useState(matchMedia.matches);
|
const [isStandalone, setIsStandalone] = useState(matchMedia.matches);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// no need to listen for events on iOS
|
if (isIOSStandalone) {
|
||||||
if (isIOSStandAlone) {
|
return () => {}; // No need to listen for events on iOS
|
||||||
return () => {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handler = (evt) => {
|
const handler = (evt) => {
|
||||||
console.log(`[useIsLaunchedPWA] App is now running ${evt.matches ? "standalone" : "in the browser"}`);
|
console.log(`[useIsLaunchedPWA] App is now running ${evt.matches ? "standalone" : "in the browser"}`);
|
||||||
setIsStandalone(evt.matches);
|
setIsStandalone(evt.matches);
|
||||||
};
|
};
|
||||||
|
|
||||||
matchMedia.addEventListener("change", handler);
|
matchMedia.addEventListener("change", handler);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
matchMedia.removeEventListener("change", handler);
|
matchMedia.removeEventListener("change", handler);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return isIOSStandAlone || isStandalone;
|
return isIOSStandalone || isStandalone;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue