kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Attempt to register sw.js on pageload
rodzic
d34eaa8be2
commit
1c7b95f12a
|
@ -8,7 +8,7 @@ import { HStack, Text, Stack } from 'soapbox/components/ui';
|
||||||
import { captureException } from 'soapbox/monitoring';
|
import { captureException } from 'soapbox/monitoring';
|
||||||
import KVStore from 'soapbox/storage/kv-store';
|
import KVStore from 'soapbox/storage/kv-store';
|
||||||
import sourceCode from 'soapbox/utils/code';
|
import sourceCode from 'soapbox/utils/code';
|
||||||
import { unregisterSw } from 'soapbox/utils/sw';
|
import { unregisterSW } from 'soapbox/utils/sw';
|
||||||
|
|
||||||
import SiteLogo from './site-logo';
|
import SiteLogo from './site-logo';
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class ErrorBoundary extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
unregisterSw().then(goHome).catch(goHome);
|
unregisterSW().then(goHome).catch(goHome);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import List, { ListItem } from 'soapbox/components/list';
|
import List, { ListItem } from 'soapbox/components/list';
|
||||||
import { HStack, Text, Column, FormActions, Button, Stack, Icon } from 'soapbox/components/ui';
|
import { HStack, Text, Column, FormActions, Button, Stack, Icon } from 'soapbox/components/ui';
|
||||||
import { unregisterSw } from 'soapbox/utils/sw';
|
import { unregisterSW } from 'soapbox/utils/sw';
|
||||||
|
|
||||||
import Indicator from './components/indicator';
|
import Indicator from './components/indicator';
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ const ServiceWorkerInfo: React.FC<IServiceWorkerInfo> = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRestart = async() => {
|
const handleRestart = async() => {
|
||||||
await unregisterSw();
|
await unregisterSW();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,14 @@ import './precheck';
|
||||||
import { default as Soapbox } from './containers/soapbox';
|
import { default as Soapbox } from './containers/soapbox';
|
||||||
import * as monitoring from './monitoring';
|
import * as monitoring from './monitoring';
|
||||||
import ready from './ready';
|
import ready from './ready';
|
||||||
|
import { registerSW } from './utils/sw';
|
||||||
|
|
||||||
// Sentry
|
// Sentry
|
||||||
monitoring.start();
|
monitoring.start();
|
||||||
|
|
||||||
// Print console warning
|
|
||||||
if (BuildConfig.NODE_ENV === 'production') {
|
if (BuildConfig.NODE_ENV === 'production') {
|
||||||
printConsoleWarning();
|
printConsoleWarning();
|
||||||
|
registerSW('/sw.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
ready(() => {
|
ready(() => {
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
|
/** Register the ServiceWorker. */
|
||||||
|
function registerSW(path: string) {
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.register(path, { scope: '/' });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Unregister the ServiceWorker */
|
/** Unregister the ServiceWorker */
|
||||||
// https://stackoverflow.com/a/49771828/8811886
|
// https://stackoverflow.com/a/49771828/8811886
|
||||||
const unregisterSw = async(): Promise<void> => {
|
const unregisterSW = async(): Promise<void> => {
|
||||||
if (navigator.serviceWorker) {
|
if (navigator.serviceWorker) {
|
||||||
// FIXME: this only works if using a single tab.
|
// FIXME: this only works if using a single tab.
|
||||||
// Send a message to sw.js instead to refresh all tabs.
|
// Send a message to sw.js instead to refresh all tabs.
|
||||||
|
@ -11,5 +20,6 @@ const unregisterSw = async(): Promise<void> => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
unregisterSw,
|
registerSW,
|
||||||
|
unregisterSW,
|
||||||
};
|
};
|
Ładowanie…
Reference in New Issue