Page MenuHomePhabricator

D12915.diff
No OneTemporary

D12915.diff

diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js
--- a/web/push-notif/push-notifs-handler.js
+++ b/web/push-notif/push-notifs-handler.js
@@ -119,6 +119,19 @@
),
[dispatch],
);
+
+ // Handle invalid device token
+ const localToken = useSelector(
+ state => state.tunnelbrokerDeviceToken.localToken,
+ );
+ const prevLocalToken = React.useRef(localToken);
+ React.useEffect(() => {
+ if (prevLocalToken.current && !localToken) {
+ electron?.fetchDeviceToken?.();
+ }
+
+ prevLocalToken.current = localToken;
+ }, [localToken]);
}
function useCreatePushSubscription(): () => Promise<void> {
@@ -271,6 +284,27 @@
navigator.serviceWorker?.removeEventListener('message', callback);
}, [dispatch, supported]);
+ // Handle invalid device token
+ const localToken = useSelector(
+ state => state.tunnelbrokerDeviceToken.localToken,
+ );
+ const prevLocalToken = React.useRef(localToken);
+ React.useEffect(() => {
+ if (
+ !navigator.serviceWorker ||
+ !supported ||
+ Notification.permission !== 'granted'
+ ) {
+ return;
+ }
+
+ if (prevLocalToken.current && !localToken) {
+ void createPushSubscription();
+ }
+
+ prevLocalToken.current = localToken;
+ }, [createPushSubscription, localToken, supported]);
+
return null;
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 1:08 PM (18 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2570746
Default Alt Text
D12915.diff (1 KB)

Event Timeline