mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-29 13:24:48 +00:00
online editor: Wait for service worker to be up in index.ts
Wait for the service worker to come up fully. The API is a bit unwieldy, but we tell to not wait and to claim all clients, so it should come up the first time round.
This commit is contained in:
parent
4108d49430
commit
dc391be74a
1 changed files with 23 additions and 4 deletions
|
@ -22,6 +22,23 @@ import {
|
||||||
Widget,
|
Widget,
|
||||||
} from "@lumino/widgets";
|
} from "@lumino/widgets";
|
||||||
|
|
||||||
|
function resolveControllerReady(resolve: () => void, count: number) {
|
||||||
|
count += 1;
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
console.info(`Controller ready after ${count} attempts`);
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
console.warn(`Controller is not ready yet ! waiting ... - (${count})`);
|
||||||
|
return setTimeout(() => {
|
||||||
|
resolveControllerReady(resolve, count);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wait_for_service_worker(): Promise<void> {
|
||||||
|
return new Promise((res, _) => resolveControllerReady(res, 0));
|
||||||
|
}
|
||||||
|
|
||||||
const lsp_waiter = new LspWaiter();
|
const lsp_waiter = new LspWaiter();
|
||||||
|
|
||||||
const commands = new CommandRegistry();
|
const commands = new CommandRegistry();
|
||||||
|
@ -440,10 +457,12 @@ function setup(lsp: Lsp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
lsp_waiter.wait_for_lsp().then((lsp: Lsp) => {
|
Promise.all([wait_for_service_worker(), lsp_waiter.wait_for_lsp()]).then(
|
||||||
setup(lsp);
|
([_, lsp]) => {
|
||||||
document.body.getElementsByClassName("loader")[0].remove();
|
setup(lsp);
|
||||||
});
|
document.body.getElementsByClassName("loader")[0].remove();
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = main;
|
window.onload = main;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue