Commit 912abfac authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Bootloader, wait for serviceworker active before finish install

parent 4c5b6ec3
......@@ -48,6 +48,29 @@ var repair = false;
});
}
function waitForServiceWorkerActive(registration) {
var serviceWorker;
if (registration.installing) {
serviceWorker = registration.installing;
} else if (registration.waiting) {
serviceWorker = registration.waiting;
} else if (registration.active) {
serviceWorker = registration.active;
}
if (serviceWorker.state !== "activated") {
RSVP.Promise(function (resolve, reject) {
serviceWorker.addEventListener('statechange', function (e) {
if (e.target.state === "activated") {
resolve();
}
});
RSVP.delay(500).then(function () {
reject(new Error("Timeout service worker install"));
});
});
}
}
rJS(window)
.setState({error_amount: 0})
.ready(function (gadget) {
......@@ -175,6 +198,9 @@ var repair = false;
"gadget_officejs_bootloader_serviceworker.js"
);
})
.push(function (registration) {
return waitForServiceWorkerActive(registration);
})
.push(undefined, function (error) {
return gadget.changeState({
error_amount: gadget.state.error_amount + 1,
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.23305.42668.58504</string> </value>
<value> <string>963.29130.48991.23978</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1510305608.12</float>
<float>1510654966.6</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment