about summary refs log tree commit diff
path: root/app/javascript/mastodon/main.js
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2022-08-26 03:10:01 +0900
committerGitHub <noreply@github.com>2022-08-25 20:10:01 +0200
commit81e1cc5fece9a431c28ca648c2dd4b1b5f643f13 (patch)
tree0ab25ce1a64ab1f40c726b907fca8f71b86f7774 /app/javascript/mastodon/main.js
parent55bef1e34fc3b07ed7f762d565a161e74e128016 (diff)
Replace to `workbox-webpack-plugin` from `offline-plugin` (#18409)
Diffstat (limited to 'app/javascript/mastodon/main.js')
-rw-r--r--app/javascript/mastodon/main.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/app/javascript/mastodon/main.js b/app/javascript/mastodon/main.js
index bda51f692..a66975bfd 100644
--- a/app/javascript/mastodon/main.js
+++ b/app/javascript/mastodon/main.js
@@ -1,9 +1,9 @@
-import * as registerPushNotifications from './actions/push_notifications';
-import { setupBrowserNotifications } from './actions/notifications';
-import { default as Mastodon, store } from './containers/mastodon';
 import React from 'react';
 import ReactDOM from 'react-dom';
-import ready from './ready';
+import * as registerPushNotifications from 'mastodon/actions/push_notifications';
+import { setupBrowserNotifications } from 'mastodon/actions/notifications';
+import Mastodon, { store } from 'mastodon/containers/mastodon';
+import ready from 'mastodon/ready';
 
 const perf = require('./performance');
 
@@ -24,10 +24,20 @@ function main() {
 
     ReactDOM.render(<Mastodon {...props} />, mountNode);
     store.dispatch(setupBrowserNotifications());
-    if (process.env.NODE_ENV === 'production') {
-      // avoid offline in dev mode because it's harder to debug
-      require('offline-plugin/runtime').install();
-      store.dispatch(registerPushNotifications.register());
+
+    if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
+      import('workbox-window')
+        .then(({ Workbox }) => {
+          const wb = new Workbox('/sw.js');
+
+          return wb.register();
+        })
+        .then(() => {
+          store.dispatch(registerPushNotifications.register());
+        })
+        .catch(err => {
+          console.error(err);
+        });
     }
     perf.stop('main()');
   });