Simplify web push UX and updates

- Use a single endpoint
- Use a declarative web push sync hook. This thus handles all edge cases
  that had to be manually handled before: logout, login, account sync,
  etc.
- Simplify UX: browser notifications are always enabled (unless denied),
  web push toggle only shows up if permissions are already granted.
This commit is contained in:
nimbleghost 2023-06-02 13:22:54 +02:00
parent 4944e3ae4b
commit 47ad024ec7
20 changed files with 294 additions and 427 deletions

View file

@ -9,7 +9,8 @@ import pruner from "../app/Pruner";
import session from "../app/Session";
import accountApi from "../app/AccountApi";
import { UnauthorizedError } from "../app/errors";
import webPushWorker from "../app/WebPushWorker";
import { webPushRefreshWorker, useWebPushUpdateWorker } from "../app/WebPushWorker";
import notifier from "../app/Notifier";
/**
* Wire connectionManager and subscriptionManager so that subscriptions are updated when the connection
@ -134,24 +135,26 @@ const stopWorkers = () => {
poller.stopWorker();
pruner.stopWorker();
accountApi.stopWorker();
webPushRefreshWorker.stopWorker();
};
const startWorkers = () => {
poller.startWorker();
pruner.startWorker();
accountApi.startWorker();
webPushRefreshWorker.startWorker();
};
export const useBackgroundProcesses = () => {
useWebPushUpdateWorker();
useEffect(() => {
console.log("[useBackgroundProcesses] mounting");
startWorkers();
webPushWorker.startWorker();
return () => {
console.log("[useBackgroundProcesses] unloading");
stopWorkers();
webPushWorker.stopWorker();
};
}, []);
};