mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 15:36:49 +08:00
fix service worker
This commit is contained in:
+2
-2
@@ -119,10 +119,10 @@ async function subscribeForPushNotifications() {
|
|||||||
async function afterLogin() {
|
async function afterLogin() {
|
||||||
// 生效主题配置
|
// 生效主题配置
|
||||||
await setTheme()
|
await setTheme()
|
||||||
// 订阅推送通知
|
|
||||||
await subscribeForPushNotifications()
|
|
||||||
// 跳转到首页或回原始页面
|
// 跳转到首页或回原始页面
|
||||||
router.push(store.state.auth.originalPath ?? '/')
|
router.push(store.state.auth.originalPath ?? '/')
|
||||||
|
// 订阅推送通知
|
||||||
|
await subscribeForPushNotifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 登录获取token事件
|
// 登录获取token事件
|
||||||
|
|||||||
+12
-4
@@ -18,12 +18,20 @@ const options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 监听 push 事件,显示通知
|
// 监听 push 事件,显示通知
|
||||||
self.addEventListener('push', function (e) {
|
self.addEventListener('push', function (event) {
|
||||||
if (!e.data) {
|
if (!event.data) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 解析获取推送消息
|
// 解析获取推送消息
|
||||||
let payload = e.data.json()
|
let payload
|
||||||
|
try {
|
||||||
|
payload = event.data?.json()
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
payload = {
|
||||||
|
title: event.data?.text(),
|
||||||
|
}
|
||||||
|
}
|
||||||
// 根据推送消息生成桌面通知并展现出来
|
// 根据推送消息生成桌面通知并展现出来
|
||||||
let promise = self.registration.showNotification(payload.title, {
|
let promise = self.registration.showNotification(payload.title, {
|
||||||
body: payload.body,
|
body: payload.body,
|
||||||
@@ -32,7 +40,7 @@ self.addEventListener('push', function (e) {
|
|||||||
url: payload.url,
|
url: payload.url,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
e.waitUntil(promise)
|
event.waitUntil(promise)
|
||||||
})
|
})
|
||||||
|
|
||||||
self.skipWaiting()
|
self.skipWaiting()
|
||||||
|
|||||||
Reference in New Issue
Block a user