From 003c31c0a19aef2dec24168b094e3af15f0e3b0c Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Mon, 21 Feb 2022 11:14:20 -0500 Subject: [PATCH] Create service worker in app --- src/App.js | 2 ++ src/services/push/push.js | 2 ++ src/sw.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/App.js b/src/App.js index abc2656f..87f8cdc1 100644 --- a/src/App.js +++ b/src/App.js @@ -14,6 +14,7 @@ import DesktopNav from './components/desktop_nav/desktop_nav.vue' import UserReportingModal from './components/user_reporting_modal/user_reporting_modal.vue' import PostStatusModal from './components/post_status_modal/post_status_modal.vue' import GlobalNoticeList from './components/global_notice_list/global_notice_list.vue' +import { getOrCreateServiceWorker } from './services/push/push' import { windowWidth, windowHeight } from './services/window_utils/window_utils' import { mapGetters } from 'vuex' @@ -45,6 +46,7 @@ export default { const val = this.$store.getters.mergedConfig.interfaceLanguage this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val }) window.addEventListener('resize', this.updateMobileState) + getOrCreateServiceWorker() }, destroyed () { window.removeEventListener('resize', this.updateMobileState) diff --git a/src/services/push/push.js b/src/services/push/push.js index 5836fc26..f0e98f91 100644 --- a/src/services/push/push.js +++ b/src/services/push/push.js @@ -109,3 +109,5 @@ export function unregisterPushNotifications (token) { ]).catch((e) => console.warn(`Failed to disable Web Push Notifications: ${e.message}`)) } } + +export { getOrCreateServiceWorker } diff --git a/src/sw.js b/src/sw.js index f5e34dd6..cc419f74 100644 --- a/src/sw.js +++ b/src/sw.js @@ -67,3 +67,5 @@ self.addEventListener('notificationclick', (event) => { if (clients.openWindow) return clients.openWindow('/') })) }) + +self.addEventListener('fetch', _ => _)