I tried any possible setup but potentially try to do something that is not meant to work conceptually.
(我尝试了所有可能的设置,但有可能尝试做一些在概念上不起作用的事情。)
I want to manually check for an update and trigger a refresh from the settings page in my app.
(我想手动检查更新并从应用程序的设置页面触发刷新。)
On "Check for update/install" I do the following (I also tried to install the eventListeners directly on navigator.serviceWorker
instead - being desperately trying out various things - but also without success): (在“检查更新/安装”上,我执行以下操作(我也尝试直接在navigator.serviceWorker
上安装eventListeners-拼命尝试各种事情-但也没有成功):)
async function updateApp() {
const reg = await navigator.serviceWorker!.ready
reg.installing && reg.installing.addEventListener('waiting', (event) => {
reg.waiting!.addEventListener('controlling', event => reloadToFinishAppUpdate())
reg.waiting!.postMessage({ type: 'SKIP_WAITING' })
})
// if already waiting
if (reg.waiting) {
reg.waiting.addEventListener('controlling', () => {
window.location.reload()
})
reg.waiting.postMessage({ type: 'SKIP_WAITING' })
}
}
Generally I would like to have a chain that can just run whether the current registration is still installing or already waiting.
(通常,我希望有一个可以运行的链,无论当前的注册仍在安装中还是已经在等待中。)
Right now, non of my event listeners work. (目前,我所有的事件监听器都无法正常工作。)
I also worked with reg.installing.onstatechange = () => { ... }
but nothing worked smoothly so far. (我还与reg.installing.onstatechange = () => { ... }
一起工作,但到目前为止没有任何工作顺利。)
What's the issue here? (这里有什么问题?)
Can I even set these type of listeners outside of sw-files? (我什至可以在sw文件之外设置这些类型的侦听器吗?)
ask by Alexei S. translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…