about summary refs log tree commit diff
path: root/app/javascript/flavours
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-08-28 13:27:17 +0200
committerGitHub <noreply@github.com>2022-08-28 13:27:17 +0200
commit215738bb3cba4951e84174b461da5f1004b0649e (patch)
treececa848b6a0553474e2b228dbf8c9e9c144cc99f /app/javascript/flavours
parent54d9a9c18a74a1ec766d8f611ad3ee11ab4c5422 (diff)
parent54ae7a221e862990550850500d70997c70187b70 (diff)
Merge pull request #1833 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours')
-rw-r--r--app/javascript/flavours/glitch/util/main.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/app/javascript/flavours/glitch/util/main.js b/app/javascript/flavours/glitch/util/main.js
index 6577b70c2..9e76774b6 100644
--- a/app/javascript/flavours/glitch/util/main.js
+++ b/app/javascript/flavours/glitch/util/main.js
@@ -1,9 +1,9 @@
-import * as registerPushNotifications from 'flavours/glitch/actions/push_notifications';
-import { setupBrowserNotifications } from 'flavours/glitch/actions/notifications';
-import { default as Mastodon, store } from 'flavours/glitch/containers/mastodon';
 import React from 'react';
 import ReactDOM from 'react-dom';
-import ready from './ready';
+import * as registerPushNotifications from 'flavours/glitch/actions/push_notifications';
+import { setupBrowserNotifications } from 'flavours/glitch/actions/notifications';
+import Mastodon, { store } from 'flavours/glitch/containers/mastodon';
+import ready from 'flavours/glitch/util/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()');
   });