Commit c3ab37b4 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs: workaround for firefox can be install big app

parent 1be16778
...@@ -39,6 +39,7 @@ var repair = false; ...@@ -39,6 +39,7 @@ var repair = false;
type: "appcache", type: "appcache",
manifest: gadget.state.cache_file, manifest: gadget.state.cache_file,
version: gadget.state.version_url, version: gadget.state.version_url,
origin_url: gadget.element.baseURI, // can be removed
take_installer: true take_installer: true
} }
}); });
...@@ -161,9 +162,13 @@ var repair = false; ...@@ -161,9 +162,13 @@ var repair = false;
}); });
}) })
.declareMethod("install", function () { .declareMethod("install", function (storage) {
var gadget = this, var gadget = this,
storage = createStorage(gadget); register;
if (!storage) {
register = true; //can be removed
}
storage = storage || createStorage(gadget); //can be removed
if (navigator.serviceWorker !== undefined) { if (navigator.serviceWorker !== undefined) {
return storage.repair() return storage.repair()
.push(undefined, function (error) { .push(undefined, function (error) {
...@@ -175,13 +180,59 @@ var repair = false; ...@@ -175,13 +180,59 @@ var repair = false;
return RSVP.delay(1000); return RSVP.delay(1000);
}) })
.push(function () { .push(function () {
return gadget.install(); return gadget.install(storage);
}); });
}) })
.push(function () { .push(function () {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
storage.get(gadget.element.baseURI),
storage.allAttachments(gadget.element.baseURI)
]);
})
.push(function (result) {
var i,
value = result[0],
applist = result[0].list,
attachs = result[1],
reinstall = false;
for (i = 0; i < applist.length; i++) {
if (!attachs.hasOwnProperty(applist[i])) {
reinstall = true; // absence files can be founded in antother document
// as example files onlyoffice_gadget put in global_setting_gadget
break;
}
}
// reinstall realy help
if (reinstall) {
value.hash = "";
return gadget.changeState({
error_amount: gadget.state.error_amount + 1,
error: "file " + applist[i] + " absence for " + gadget.element.baseURI
})
.push(function () {
return jIO.createJIO({
type: "indexeddb",
database: "ojs_source_code"
}).put(gadget.element.baseURI, value);
})
.push(function () {
// hash know that file synced, so remove hash
return window.indexedDB.deleteDatabase('jio:officejs-hash');
})
.push(function () {
return gadget.install(storage);
});
}
});
})
.push(function () {
if (register) {
return navigator.serviceWorker.register( return navigator.serviceWorker.register(
"gadget_officejs_bootloader_serviceworker.js" "gadget_officejs_bootloader_serviceworker.js"
); );
}
}); });
} }
return; return;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
this._documents = {}; this._documents = {};
// Harcoded here, find a better way. // Harcoded here, find a better way.
if (this._take_installer) { if (this._take_installer) {
this._relative_url_list = [ this._installer_url_list = [
this._prefix + "/", this._prefix + "/",
this._prefix + "gadget_officejs_bootloader.js", this._prefix + "gadget_officejs_bootloader.js",
this._prefix + "gadget_officejs_bootloader_presentation.html", this._prefix + "gadget_officejs_bootloader_presentation.html",
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
this._prefix + "jio_appcachestorage.js" this._prefix + "jio_appcachestorage.js"
]; ];
} else { } else {
this._relative_url_list = [this._prefix + "/"]; this._installer_url_list = [this._prefix + "/"];
} }
if (this._take_installer) { if (this._take_installer) {
this._version = 'app/'; this._version = 'app/';
...@@ -108,11 +108,14 @@ ...@@ -108,11 +108,14 @@
}) })
.push(function (response) { .push(function (response) {
var text = response.target.responseText, var text = response.target.responseText,
relative_url_list = text.split('\n'), relative_url_list = text.replace("\r\n", "\n").split('\n'),
i, i,
take = false, take = false,
hash = rusha.digestFromString(text); value = {};
storage._documents[storage._origin_url] = {'hash': hash}; storage._relative_url_list = [];
storage._gadget_list = [];
storage._relative_url_list =
storage._relative_url_list.concat(storage._installer_url_list);
storage._relative_url_list.push(storage._version); storage._relative_url_list.push(storage._version);
storage._relative_url_list.push(storage._version + storage._manifest); storage._relative_url_list.push(storage._version + storage._manifest);
for (i = 0; i < relative_url_list.length; i += 1) { for (i = 0; i < relative_url_list.length; i += 1) {
...@@ -135,6 +138,15 @@ ...@@ -135,6 +138,15 @@
take = 1; take = 1;
} }
} }
storage._relative_url_list.sort();
storage._gadget_list.sort();
value.hash = rusha.digestFromString(
storage._relative_url_list.join('\n') +
"GADGETS\n" + storage._gadget_list.join('\n')
);
value.list = storage._relative_url_list.concat(storage._gadget_list);
value.list.sort();
storage._documents[storage._origin_url] = value;
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
if (!error.message) { if (!error.message) {
......
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