aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-02-26 21:03:34 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-05-04 13:02:56 -0400
commitf2a5d5095931a78dc388d4cba66953560a336e7f (patch)
tree383b42f3b616c033d24f62b8d883121f6687558f /ext/bg
parentd96d4b0658de9eeb272a57966a07a7798da09433 (diff)
Database changes automatically update storage stats
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/settings.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 99463593..49bf264d 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -364,6 +364,10 @@ async function onDictionaryPurge(e) {
dictControls.show();
dictProgress.hide();
+
+ if (storageEstimate.mostRecent !== null) {
+ storageUpdateStats();
+ }
}
}
@@ -377,7 +381,12 @@ async function onDictionaryImport(e) {
dictionarySpinnerShow(true);
const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
- const updateProgress = (total, current) => setProgress(current / total * 100.0);
+ const updateProgress = (total, current) => {
+ setProgress(current / total * 100.0);
+ if (storageEstimate.mostRecent !== null && !storageUpdateStats.isUpdating) {
+ storageUpdateStats();
+ }
+ };
setProgress(0.0);
const exceptions = [];
@@ -588,16 +597,17 @@ function storageBytesToLabeledString(size) {
size /= base;
++labelIndex;
}
- const label = size.toFixed(1).replace(/\.0+$/, "");
+ const label = size.toFixed(1);
return `${label}${labels[labelIndex]}`;
}
async function storageEstimate() {
try {
- return await navigator.storage.estimate();
+ return (storageEstimate.mostRecent = await navigator.storage.estimate());
} catch (e) { }
return null;
}
+storageEstimate.mostRecent = null;
async function storageInfoInitialize() {
const browser = await getBrowser();
@@ -611,8 +621,8 @@ async function storageInfoInitialize() {
document.querySelector("#storage-refresh").addEventListener('click', () => storageShowInfo(), false);
}
-async function storageShowInfo() {
- storageSpinnerShow(true);
+async function storageUpdateStats() {
+ storageUpdateStats.isUpdating = true;
const estimate = await storageEstimate();
const valid = (estimate !== null);
@@ -621,6 +631,16 @@ async function storageShowInfo() {
document.querySelector("#storage-usage").textContent = storageBytesToLabeledString(estimate.usage);
document.querySelector("#storage-quota").textContent = storageBytesToLabeledString(estimate.quota);
}
+
+ storageUpdateStats.isUpdating = false;
+ return valid;
+}
+storageUpdateStats.isUpdating = false;
+
+async function storageShowInfo() {
+ storageSpinnerShow(true);
+
+ const valid = await storageUpdateStats();
document.querySelector("#storage-use").classList.toggle("storage-hidden", !valid);
document.querySelector("#storage-error").classList.toggle("storage-hidden", valid);