Skip to content

Commit

Permalink
slintpad: Reload if service worker does not come up
Browse files Browse the repository at this point in the history
Apparently browsers do not set a controlling service worker when
force-reloading a page. Work around this by reloading the page.

We run into this issue only while the load screen is still up. So we
have no state to take care of or anything, so go for the simplest
thinkable "fix": Reload the page.
  • Loading branch information
hunger committed Mar 30, 2023
1 parent 225fa93 commit 1f8643b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/slintpad/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ import {

function resolveControllerReady(resolve: () => void, count: number) {
count += 1;
if (count >= 5) {
// Force a reload! We do not have any state yet, so we do not need to
// be creative to make the browser notice that we have an active
// service worker.
window.location.reload();
}
if (navigator.serviceWorker.controller) {
console.info(`Controller ready after ${count} attempts`);
resolve();
Expand Down

0 comments on commit 1f8643b

Please sign in to comment.