Commit 4bcd6523 authored by Vincent Bechu's avatar Vincent Bechu Committed by Eteri

[erp5_officejs] Bootloader, test service worker presence and retry install on error

parent 8a8120f6
...@@ -47,9 +47,8 @@ var repair = false; ...@@ -47,9 +47,8 @@ var repair = false;
.ready(function (gadget) { .ready(function (gadget) {
var i, var i,
state = {}, state = {},
sub_gadget_list = [],
element_list = element_list =
gadget.element.querySelectorAll('[data-install-configuration]'); gadget.element.querySelectorAll('[data-install-configuration]');
window.Bootloader = gadget; window.Bootloader = gadget;
for (i = 0; i < element_list.length; i += 1) { for (i = 0; i < element_list.length; i += 1) {
...@@ -58,6 +57,14 @@ var repair = false; ...@@ -58,6 +57,14 @@ var repair = false;
} }
state.redirect_url = new URL(window.location); state.redirect_url = new URL(window.location);
state.redirect_url.pathname += state.version_url; state.redirect_url.pathname += state.version_url;
// This is a bad hack to support dropbox.
if (state.redirect_url.hash &&
state.redirect_url.hash.startsWith('#access_token')) {
state.redirect_url.hash = state.redirect_url.hash.replace(
'#access_token',
'#/?page=ojs_dropbox_configurator&access_token'
);
}
return gadget.changeState(state); return gadget.changeState(state);
}) })
...@@ -68,15 +75,7 @@ var repair = false; ...@@ -68,15 +75,7 @@ var repair = false;
.declareService(function () { .declareService(function () {
var gadget = this; var gadget = this;
return new RSVP.Queue() return gadget.isChildren()
.push(function () {
/* Workaround for renderjs issue,
sub gadget does not have all aquired Method at this point*/
return RSVP.delay(500);
})
.push(function () {
return gadget.isChildren();
})
.push(undefined, function (error) { .push(undefined, function (error) {
if (error instanceof rJS.AcquisitionError) { if (error instanceof rJS.AcquisitionError) {
return RSVP.all([ return RSVP.all([
...@@ -131,6 +130,7 @@ sub gadget does not have all aquired Method at this point*/ ...@@ -131,6 +130,7 @@ sub gadget does not have all aquired Method at this point*/
return this.declareGadget(url, return this.declareGadget(url,
{ {
"element": element, "element": element,
"scope": url,
"sandbox": "iframe" "sandbox": "iframe"
}) })
.push(function (sub_gadget) { .push(function (sub_gadget) {
...@@ -141,30 +141,28 @@ sub gadget does not have all aquired Method at this point*/ ...@@ -141,30 +141,28 @@ sub gadget does not have all aquired Method at this point*/
.declareMethod("install", function () { .declareMethod("install", function () {
var gadget = this, var gadget = this,
storage = createStorage(gadget); storage = createStorage(gadget);
return new RSVP.Queue() if (navigator.serviceWorker !== undefined) {
.push(function () { return storage.repair()
return navigator.serviceWorker.register( .push(undefined, function (error) {
"gadget_officejs_bootloader_serviceworker.js"
);
})
.push(function () {
return storage.repair();
})
.push(undefined, function (error) {
if (gadget.state.retry !== undefined) {
return gadget.changeState({ return gadget.changeState({
retry: gadget.state.retry += 1, retry: gadget.state.retry !== undefined ?
gadget.state.retry + 1 : 0,
error: error error: error
}) })
.push(function () { .push(function () {
return RSVP.delay(1000); return RSVP.delay(1000);
}) })
.push(function () { .push(function () {
return gadget.install(); return gadget.install();
}); });
} })
throw error; .push(function () {
}); return navigator.serviceWorker.register(
"gadget_officejs_bootloader_serviceworker.js"
);
});
}
return;
}); });
}(window, document, RSVP, rJS, jIO, navigator, URL)); }(window, document, RSVP, rJS, jIO, navigator, URL));
\ No newline at end of file
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.10581.61261.18995</string> </value> <value> <string>961.29242.42246.47598</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1501763880.35</float> <float>1502886442.31</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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