Further generalize storage controller by supporting lists of nodes (#906)
This commit is contained in:
parent
199dd7d763
commit
19e0346484
@ -23,22 +23,20 @@ class StorageController {
|
|||||||
this._persistentStorageCheckbox = false;
|
this._persistentStorageCheckbox = false;
|
||||||
this._storageUsageNode = null;
|
this._storageUsageNode = null;
|
||||||
this._storageQuotaNode = null;
|
this._storageQuotaNode = null;
|
||||||
this._storageUseFiniteNode = null;
|
this._storageUseFiniteNodes = null;
|
||||||
this._storageUseInfiniteNode = null;
|
this._storageUseInfiniteNodes = null;
|
||||||
this._storageUseUndefinedNode = null;
|
this._storageUseValidNodes = null;
|
||||||
this._storageUseNode = null;
|
this._storageUseInvalidNodes = null;
|
||||||
this._storageErrorNode = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
this._persistentStorageCheckbox = document.querySelector('#storage-persistent-checkbox');
|
this._persistentStorageCheckbox = document.querySelector('#storage-persistent-checkbox');
|
||||||
this._storageUsageNode = document.querySelector('#storage-usage');
|
this._storageUsageNode = document.querySelector('#storage-usage');
|
||||||
this._storageQuotaNode = document.querySelector('#storage-quota');
|
this._storageQuotaNode = document.querySelector('#storage-quota');
|
||||||
this._storageUseFiniteNode = document.querySelector('#storage-use-finite');
|
this._storageUseFiniteNodes = document.querySelectorAll('#storage-use-finite');
|
||||||
this._storageUseInfiniteNode = document.querySelector('#storage-use-infinite');
|
this._storageUseInfiniteNodes = document.querySelectorAll('#storage-use-infinite');
|
||||||
this._storageUseUndefinedNode = document.querySelector('#storage-use-undefined');
|
this._storageUseValidNodes = document.querySelectorAll('#storage-use-valid');
|
||||||
this._storageUseNode = document.querySelector('#storage-use');
|
this._storageUseInvalidNodes = document.querySelectorAll('#storage-use-invalid');
|
||||||
this._storageErrorNode = document.querySelector('#storage-error');
|
|
||||||
|
|
||||||
this._preparePersistentStorage();
|
this._preparePersistentStorage();
|
||||||
this.updateStats();
|
this.updateStats();
|
||||||
@ -55,20 +53,17 @@ class StorageController {
|
|||||||
const estimate = await this._storageEstimate();
|
const estimate = await this._storageEstimate();
|
||||||
const valid = (estimate !== null);
|
const valid = (estimate !== null);
|
||||||
|
|
||||||
if (valid) {
|
// Firefox reports usage as 0 when persistent storage is enabled.
|
||||||
// Firefox reports usage as 0 when persistent storage is enabled.
|
const finite = valid && (estimate.usage > 0 || !(await this._isStoragePeristent()));
|
||||||
const finite = (estimate.usage > 0 || !(await this._isStoragePeristent()));
|
if (finite) {
|
||||||
if (finite) {
|
this._storageUsageNode.textContent = this._bytesToLabeledString(estimate.usage);
|
||||||
this._storageUsageNode.textContent = this._bytesToLabeledString(estimate.usage);
|
this._storageQuotaNode.textContent = this._bytesToLabeledString(estimate.quota);
|
||||||
this._storageQuotaNode.textContent = this._bytesToLabeledString(estimate.quota);
|
|
||||||
}
|
|
||||||
this._storageUseFiniteNode.hidden = !finite;
|
|
||||||
this._storageUseInfiniteNode.hidden = finite;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._storageUseUndefinedNode !== null) { this._storageUseUndefinedNode.hidden = !valid; }
|
this._setElementsVisible(this._storageUseFiniteNodes, valid && finite);
|
||||||
if (this._storageUseNode !== null) { this._storageUseNode.hidden = !valid; }
|
this._setElementsVisible(this._storageUseInfiniteNodes, valid && !finite);
|
||||||
if (this._storageErrorNode !== null) { this._storageErrorNode.hidden = valid; }
|
this._setElementsVisible(this._storageUseValidNodes, valid);
|
||||||
|
this._setElementsVisible(this._storageUseInvalidNodes, !valid);
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
} finally {
|
} finally {
|
||||||
@ -173,4 +168,11 @@ class StorageController {
|
|||||||
checkbox.checked = isStoragePeristent;
|
checkbox.checked = isStoragePeristent;
|
||||||
checkbox.readOnly = isStoragePeristent;
|
checkbox.readOnly = isStoragePeristent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_setElementsVisible(elements, visible) {
|
||||||
|
visible = !visible;
|
||||||
|
for (const element of elements) {
|
||||||
|
element.hidden = visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -805,7 +805,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="storage-use" hidden>
|
<div id="storage-use" hidden>
|
||||||
<p class="help-block" id="storage-use-undefined">
|
<p class="help-block" id="storage-use-invalid">
|
||||||
Yomichan is using an indeterminate amount of storage.
|
Yomichan is using an indeterminate amount of storage.
|
||||||
</p>
|
</p>
|
||||||
<p class="help-block" id="storage-use-finite" hidden>
|
<p class="help-block" id="storage-use-finite" hidden>
|
||||||
|
Loading…
Reference in New Issue
Block a user