summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-09-13 22:43:16 -0700
committerAlex Yatskov <alex@foosoft.net>2016-09-13 22:43:16 -0700
commitff3896ed01024e612f9a80fb898f84afac98fc6b (patch)
tree1da02ec14bc0526f53de2a21b2d23ac652c25cd8
parent17366e521afe2dd3b32f2068db43f972ce89b36f (diff)
Fix progress counting
-rw-r--r--ext/bg/js/dictionary.js4
-rw-r--r--ext/bg/js/translator.js19
-rw-r--r--ext/bg/js/yomichan.js6
3 files changed, 20 insertions, 9 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 2bd39344..738535bb 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(i, index.banks);
+ callback(indexUrl, i, index.banks);
}
});
});
@@ -199,7 +199,7 @@ class Dictionary {
return this.db.kanji.bulkAdd(rows).then(() => {
if (callback) {
- callback(i, index.banks);
+ callback(indexUrl, i, index.banks);
}
});
});
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 1dc0dca1..6827b5bc 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -45,14 +45,21 @@ class Translator {
callback({state: 'begin', progress: 0});
}
- let banksLoaded = 0;
- let banksTotal = 0;
+ const banks = {};
+ const bankCallback = (indexUrl, loaded, total) => {
+ banks[indexUrl] = {loaded: loaded, total: total};
+ if (Object.keys(banks).length !== 3) {
+ return;
+ }
- const bankCallback = (loaded, total) => {
- banksLoaded += loaded;
- banksTotal += total;
+ let banksLoaded = 0;
+ let banksTotal = 0;
+ for (const url in banks) {
+ banksLoaded += banks[url].loaded;
+ banksTotal += banks[url].total;
+ }
- if (callback) {
+ if (callback && banksTotal > 0) {
callback({state: 'update', progress: Math.ceil(100 * banksLoaded / banksTotal)});
}
};
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 10a42f47..c9f53253 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -47,6 +47,10 @@ class Yomichan {
}
}
+ onImport({state, progress}) {
+ console.log(`${state}: ${progress}`);
+ }
+
onMessage(request, sender, callback) {
const {action, params} = request, method = this['api_' + action];
@@ -90,7 +94,7 @@ class Yomichan {
break;
case 'loading':
chrome.browserAction.setBadgeText({text: '...'});
- this.translator.loadData().then(() => this.setState('enabled'));
+ this.translator.loadData(this.onImport.bind(this)).then(() => this.setState('enabled'));
break;
}