MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / reloadSW

Function reloadSW

src/global.jsx:23–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 const e = event;
22
23 const reloadSW = async () => {
24 // Check if there is sw whose state is waiting in ServiceWorkerRegistration
25 // https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
26 const worker = e.detail && e.detail.waiting;
27
28 if (!worker) {
29 return true;
30 } // Send skip-waiting event to waiting SW with MessageChannel
31
32 await new Promise((resolve, reject) => {
33 const channel = new MessageChannel();
34
35 channel.port1.onmessage = msgEvent => {
36 if (msgEvent.data.error) {
37 reject(msgEvent.data.error);
38 } else {
39 resolve(msgEvent.data);
40 }
41 };
42
43 worker.postMessage(
44 {
45 type: 'skip-waiting',
46 },
47 [channel.port2],
48 );
49 }); // Refresh current page to use the updated HTML and other assets after SW has skiped waiting
50
51 window.location.reload(true);
52 return true;
53 };
54
55 const key = `open${Date.now()}`;
56 const btn = (

Callers 1

global.jsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected