Style changes
parent
dbd8ed14bf
commit
94fb23ba17
|
@ -122,9 +122,7 @@ class SubscriptionManager {
|
||||||
|
|
||||||
async updateWebPushSubscriptions(presetTopics) {
|
async updateWebPushSubscriptions(presetTopics) {
|
||||||
const topics = presetTopics ?? (await this.webPushTopics());
|
const topics = presetTopics ?? (await this.webPushTopics());
|
||||||
|
|
||||||
const hasWebPushTopics = topics.length > 0;
|
const hasWebPushTopics = topics.length > 0;
|
||||||
|
|
||||||
const browserSubscription = await notifier.webPushSubscription(hasWebPushTopics);
|
const browserSubscription = await notifier.webPushSubscription(hasWebPushTopics);
|
||||||
|
|
||||||
if (!browserSubscription) {
|
if (!browserSubscription) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ const broadcastChannel = new BroadcastChannel("web-push-broadcast");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the Web Push subscriptions when the list of topics changes,
|
* Updates the Web Push subscriptions when the list of topics changes,
|
||||||
* as well as plays a sound when a new broadcat message is received from
|
* as well as plays a sound when a new broadcast message is received from
|
||||||
* the service worker, since the service worker cannot play sounds.
|
* the service worker, since the service worker cannot play sounds.
|
||||||
*/
|
*/
|
||||||
const useWebPushListener = (topics) => {
|
const useWebPushListener = (topics) => {
|
||||||
|
@ -20,11 +20,11 @@ const useWebPushListener = (topics) => {
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
console.log("[useWebPushTopicListener] Refreshing web push subscriptions", topics);
|
console.log("[useWebPushListener] Refreshing web push subscriptions", topics);
|
||||||
await subscriptionManager.updateWebPushSubscriptions(topics);
|
await subscriptionManager.updateWebPushSubscriptions(topics);
|
||||||
setLastTopics(topics);
|
setLastTopics(topics);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[useWebPushTopicListener] Error refreshing web push subscriptions", e);
|
console.error("[useWebPushListener] Error refreshing web push subscriptions", e);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [topics, lastTopics]);
|
}, [topics, lastTopics]);
|
||||||
|
|
|
@ -136,9 +136,12 @@ export const useAutoSubscribe = (subscriptions, selected) => {
|
||||||
}, [params, subscriptions, selected, hasRun]);
|
}, [params, subscriptions, selected, hasRun]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watches the "display-mode" to detect if the app is running as a standalone app (PWA),
|
||||||
|
* and enables "Web Push" if it is.
|
||||||
|
*/
|
||||||
export const useStandaloneAutoWebPushSubscribe = () => {
|
export const useStandaloneAutoWebPushSubscribe = () => {
|
||||||
const matchMedia = window.matchMedia("(display-mode: standalone)");
|
const matchMedia = window.matchMedia("(display-mode: standalone)");
|
||||||
|
|
||||||
const [isStandalone, setIsStandalone] = useState(isLaunchedPWA());
|
const [isStandalone, setIsStandalone] = useState(isLaunchedPWA());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -157,7 +160,7 @@ export const useStandaloneAutoWebPushSubscribe = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isStandalone) {
|
if (isStandalone) {
|
||||||
console.log(`[useStandaloneAutoWebPushSubscribe] Turning on web push automatically`);
|
console.log(`[useStandaloneAutoWebPushSubscribe] Turning on web push automatically`);
|
||||||
prefs.setWebPushEnabled(true);
|
prefs.setWebPushEnabled(true); // Dangle!
|
||||||
}
|
}
|
||||||
}, [isStandalone]);
|
}, [isStandalone]);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue