mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-02-18 13:29:36 +01:00
Prompt for reload when new service worker is available (#1588)
This commit is contained in:
parent
ece631b430
commit
ad81033a78
@ -40,6 +40,7 @@ export enum EVENT {
|
|||||||
GESTURE_CHANGE = "gesturechange",
|
GESTURE_CHANGE = "gesturechange",
|
||||||
POINTER_MOVE = "pointermove",
|
POINTER_MOVE = "pointermove",
|
||||||
POINTER_UP = "pointerup",
|
POINTER_UP = "pointerup",
|
||||||
|
STATE_CHANGE = "statechange",
|
||||||
WHEEL = "wheel",
|
WHEEL = "wheel",
|
||||||
TOUCH_START = "touchstart",
|
TOUCH_START = "touchstart",
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import ReactDOM from "react-dom";
|
|||||||
import * as Sentry from "@sentry/browser";
|
import * as Sentry from "@sentry/browser";
|
||||||
import * as SentryIntegrations from "@sentry/integrations";
|
import * as SentryIntegrations from "@sentry/integrations";
|
||||||
|
|
||||||
|
import { EVENT } from "./constants";
|
||||||
import { TopErrorBoundary } from "./components/TopErrorBoundary";
|
import { TopErrorBoundary } from "./components/TopErrorBoundary";
|
||||||
import { IsMobileProvider } from "./is-mobile";
|
import { IsMobileProvider } from "./is-mobile";
|
||||||
import App from "./components/App";
|
import App from "./components/App";
|
||||||
@ -69,4 +70,21 @@ ReactDOM.render(
|
|||||||
rootElement,
|
rootElement,
|
||||||
);
|
);
|
||||||
|
|
||||||
registerServiceWorker();
|
registerServiceWorker({
|
||||||
|
onUpdate: (registration) => {
|
||||||
|
const waitingServiceWorker = registration.waiting;
|
||||||
|
if (waitingServiceWorker) {
|
||||||
|
waitingServiceWorker.addEventListener(
|
||||||
|
EVENT.STATE_CHANGE,
|
||||||
|
(event: Event) => {
|
||||||
|
const target = event.target as ServiceWorker;
|
||||||
|
const state = target.state as ServiceWorkerState;
|
||||||
|
if (state === "activated") {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
waitingServiceWorker.postMessage({ type: "SKIP_WAITING" });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user