fix(sw): disable skipWaiting to preserve old user notifications
Revert the automatic skipping of the waiting phase in the install event handler. Previously, self.skipWaiting() was called, which forces the new Service Worker to activate immediately. This change disables that behavior to ensure that users with older versions of the app can continue receiving notifications without interruption during the update process. Added a console log to track the installation phase for debugging purposes.
This commit is contained in:
parent
5c885eb3fa
commit
7cbf6562f0
@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { useNotificationToken } from "@/hooks/useNotificationToken";
|
import { useNotificationToken } from "@/hooks/useNotificationToken";
|
||||||
import { useNotificationTokenAPI } from "@/hooks/useNotificationTokenAPI";
|
import { useNotificationTokenAPI } from "@/hooks/useNotificationTokenAPI";
|
||||||
import { NOTIFICATION_TOKEN_KEY } from "@/utils/constants";
|
import { NOTIFICATION_TOKEN_KEY } from "@/utils/constants";
|
||||||
|
import { App } from "antd";
|
||||||
|
|
||||||
export const useAutoUpdateNotificationToken = () => {
|
export const useAutoUpdateNotificationToken = () => {
|
||||||
const [token] = useNotificationToken();
|
const [token] = useNotificationToken();
|
||||||
@ -11,6 +12,7 @@ export const useAutoUpdateNotificationToken = () => {
|
|||||||
unsetTokenReq,
|
unsetTokenReq,
|
||||||
} = useNotificationTokenAPI();
|
} = useNotificationTokenAPI();
|
||||||
const [isNotificationEnable, setIsNotificationEnable] = useState<boolean>(false);
|
const [isNotificationEnable, setIsNotificationEnable] = useState<boolean>(false);
|
||||||
|
const { message } = App.useApp();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
isTokenSetedReq.runAsync(token).then(res => {
|
isTokenSetedReq.runAsync(token).then(res => {
|
||||||
@ -30,6 +32,10 @@ export const useAutoUpdateNotificationToken = () => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.debug('Auto udpate token', token);
|
console.debug('Auto udpate token', token);
|
||||||
|
message.open({
|
||||||
|
key: 'auto-update-token',
|
||||||
|
content: `通知 Token 已更新`,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, [updateTokenReq, unsetTokenReq, isNotificationEnable, token]);
|
}, [updateTokenReq, unsetTokenReq, isNotificationEnable, token]);
|
||||||
}
|
}
|
||||||
@ -14,9 +14,8 @@ const messaging = getMessaging(app);
|
|||||||
|
|
||||||
// 1. 监听安装事件
|
// 1. 监听安装事件
|
||||||
self.addEventListener('install', (event) => {
|
self.addEventListener('install', (event) => {
|
||||||
// console.log('新版本 Service Worker 安装中...');
|
console.log('新版本 Service Worker 安装中...');
|
||||||
// 强制跳过等待阶段,直接进入激活阶段
|
// 不能强制更新,会影响旧版本用户的通知
|
||||||
self.skipWaiting();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('activate', (event) => {
|
self.addEventListener('activate', (event) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user