import{Modal,message}from'antd';import{formatMessage}from'umi/locale';// Notify user if offline nowwindow.addEventListener('sw.offline',()=>{message.warning(formatMessage({id:'app.pwa.offline'}));});// Pop up a prompt on the page asking the user if they want to use the latest versionwindow.addEventListener('sw.updated',e=>{Modal.confirm({title:formatMessage({id:'app.pwa.serviceworker.updated'}),content:formatMessage({id:'app.pwa.serviceworker.updated.hint'}),okText:formatMessage({id:'app.pwa.serviceworker.updated.ok'}),onOk:async()=>{// Check if there is sw whose state is waiting in ServiceWorkerRegistration// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistrationconstworker=e.detail&&e.detail.waiting;if(!worker){returnPromise.resolve();}// Send skip-waiting event to waiting SW with MessageChannelawaitnewPromise((resolve,reject)=>{constchannel=newMessageChannel();channel.port1.onmessage=event=>{if(event.data.error){reject(event.data.error);}else{resolve(event.data);}};worker.postMessage({type:'skip-waiting'},[channel.port2]);});// Refresh current page to use the updated HTML and other assets after SW has skiped waitingwindow.location.reload(true);returntrue;},});});