diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-09-14 20:08:49 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-09-14 20:08:49 -0700 |
commit | b9d53f8427dde34900799295287c634a68d00687 (patch) | |
tree | 4c617bce8e861e06bf54c44c7fd1f4230c6b2468 | |
parent | ff3896ed01024e612f9a80fb898f84afac98fc6b (diff) |
Progress update
-rw-r--r-- | ext/bg/js/dictionary.js | 4 | ||||
-rw-r--r-- | ext/bg/js/translator.js | 19 |
2 files changed, 10 insertions, 13 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 738535bb..4562c821 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -163,7 +163,7 @@ class Dictionary { return this.db.terms.bulkAdd(rows).then(() => { if (callback) { - callback(indexUrl, i, index.banks); + callback(i, index.banks, indexUrl); } }); }); @@ -199,7 +199,7 @@ class Dictionary { return this.db.kanji.bulkAdd(rows).then(() => { if (callback) { - callback(indexUrl, i, index.banks); + callback(i, index.banks, indexUrl); } }); }); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 6827b5bc..2331bde7 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -46,21 +46,18 @@ class Translator { } const banks = {}; - const bankCallback = (indexUrl, loaded, total) => { - banks[indexUrl] = {loaded: loaded, total: total}; - if (Object.keys(banks).length !== 3) { - return; - } + const bankCallback = (loaded, total, indexUrl) => { + banks[indexUrl] = {loaded, total}; - let banksLoaded = 0; - let banksTotal = 0; + let percent = 0.0; for (const url in banks) { - banksLoaded += banks[url].loaded; - banksTotal += banks[url].total; + percent += banks[url].loaded / banks[url].total; } - if (callback && banksTotal > 0) { - callback({state: 'update', progress: Math.ceil(100 * banksLoaded / banksTotal)}); + percent /= 3; + + if (callback) { + callback({state: 'update', progress: Math.ceil(100 * percent)}); } }; |