From 174496c71d14bb77486de37c64e35c5eb1b8fa8d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 31 May 2022 20:46:40 -0500 Subject: [PATCH 1/9] ServiceWorker: skipWaiting and reload tabs when new ServiceWorker is ready --- app/soapbox/main.tsx | 10 +++++++++- webpack/production.js | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/soapbox/main.tsx b/app/soapbox/main.tsx index 9505ae07a..9347d796c 100644 --- a/app/soapbox/main.tsx +++ b/app/soapbox/main.tsx @@ -31,7 +31,15 @@ function main() { if (BuildConfig.NODE_ENV === 'production') { // avoid offline in dev mode because it's harder to debug - OfflinePluginRuntime.install(); + // https://github.com/NekR/offline-plugin/pull/201#issuecomment-285133572 + OfflinePluginRuntime.install({ + onUpdateReady: function() { + OfflinePluginRuntime.applyUpdate(); + }, + onUpdated: function() { + window.location.reload(); + }, + }); } perf.stop('main()'); }); diff --git a/webpack/production.js b/webpack/production.js index 18666a109..c90decd4e 100644 --- a/webpack/production.js +++ b/webpack/production.js @@ -85,6 +85,7 @@ module.exports = merge(sharedConfig, { ServiceWorker: { cacheName: 'soapbox', entry: join(__dirname, '../app/soapbox/service_worker/entry.ts'), + events: true, minify: true, }, cacheMaps: [{ From 3e205a9610811ca9ec1dd3f374432148bca2d3e7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 23 Jun 2022 15:20:41 -0500 Subject: [PATCH 2/9] ServiceWorker: click toast to install update (dirty) --- app/soapbox/actions/snackbar.ts | 26 ++++++++++++------- .../ui/containers/notifications_container.js | 9 ++++++- app/soapbox/main.tsx | 6 ++++- app/soapbox/reducers/alerts.ts | 1 + app/soapbox/selectors/index.ts | 1 + 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/soapbox/actions/snackbar.ts b/app/soapbox/actions/snackbar.ts index c2fd5f32d..485537ea8 100644 --- a/app/soapbox/actions/snackbar.ts +++ b/app/soapbox/actions/snackbar.ts @@ -2,24 +2,32 @@ import { ALERT_SHOW } from './alerts'; import type { MessageDescriptor } from 'react-intl'; -export type SnackbarActionSeverity = 'info' | 'success' | 'error' +export type SnackbarActionSeverity = 'info' | 'success' | 'error'; -type SnackbarMessage = string | MessageDescriptor +type SnackbarMessage = string | MessageDescriptor; export type SnackbarAction = { - type: typeof ALERT_SHOW - message: SnackbarMessage - actionLabel?: SnackbarMessage - actionLink?: string - severity: SnackbarActionSeverity -} + type: typeof ALERT_SHOW, + message: SnackbarMessage, + actionLabel?: SnackbarMessage, + actionLink?: string, + action?: () => void, + severity: SnackbarActionSeverity, +}; -export const show = (severity: SnackbarActionSeverity, message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string): SnackbarAction => ({ +export const show = ( + severity: SnackbarActionSeverity, + message: SnackbarMessage, + actionLabel?: SnackbarMessage, + actionLink?: string, + action?: () => void, +): SnackbarAction => ({ type: ALERT_SHOW, message, actionLabel, actionLink, severity, + action, }); export const info = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) => diff --git a/app/soapbox/features/ui/containers/notifications_container.js b/app/soapbox/features/ui/containers/notifications_container.js index b7d10c9e4..50343fd10 100644 --- a/app/soapbox/features/ui/containers/notifications_container.js +++ b/app/soapbox/features/ui/containers/notifications_container.js @@ -4,6 +4,8 @@ import { NotificationStack } from 'react-notification'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; +import { Button } from 'soapbox/components/ui'; + import { dismissAlert } from '../../../actions/alerts'; import { getAlerts } from '../../../selectors'; @@ -33,7 +35,12 @@ const mapStateToProps = (state, { intl }) => { } }); - if (notification.actionLabel) { + if (notification.action) { + const { action } = notification; + notification.action = ( +