Skip to content

Commit

Permalink
Add warning if available storage space is low (#548)
Browse files Browse the repository at this point in the history
* Add warning if storage space is low

* b -> strong
  • Loading branch information
ThisIsntTheWay authored Jan 21, 2024
1 parent 2de19c4 commit 1452569
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ext/js/pages/settings/storage-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class StorageController {
/** @type {?NodeListOf<HTMLElement>} */
this._storageUseFiniteNodes = null;
/** @type {?NodeListOf<HTMLElement>} */
this._storageUseExhaustWarnNodes = null;
/** @type {?NodeListOf<HTMLElement>} */
this._storageUseInfiniteNodes = null;
/** @type {?NodeListOf<HTMLElement>} */
this._storageUseValidNodes = null;
Expand All @@ -51,6 +53,7 @@ export class StorageController {
this._storageUsageNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-usage'));
this._storageQuotaNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-quota'));
this._storageUseFiniteNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-use-finite'));
this._storageUseExhaustWarnNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-exhaustion-alert'));
this._storageUseInfiniteNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-use-infinite'));
this._storageUseValidNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-use-valid'));
this._storageUseInvalidNodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.storage-use-invalid'));
Expand Down Expand Up @@ -84,13 +87,19 @@ export class StorageController {

const estimate = await this._storageEstimate();
const valid = (estimate !== null);
let storageIsLow = false;

// Firefox reports usage as 0 when persistent storage is enabled.
const finite = valid && ((typeof estimate.usage === 'number' && estimate.usage > 0) || !(await this._persistentStorageController.isStoragePeristent()));
if (finite) {
let {usage, quota} = estimate;

if (typeof usage !== 'number') { usage = 0; }
if (typeof quota !== 'number') { quota = 0; }
if (typeof quota !== 'number') {
quota = 0;
} else {
storageIsLow = quota <= (3 * 1000000000);
}
const usageString = this._bytesToLabeledString(usage);
const quotaString = this._bytesToLabeledString(quota);
for (const node of /** @type {NodeListOf<HTMLElement>} */ (this._storageUsageNodes)) {
Expand All @@ -105,6 +114,7 @@ export class StorageController {
this._setElementsVisible(this._storageUseInfiniteNodes, valid && !finite);
this._setElementsVisible(this._storageUseValidNodes, valid);
this._setElementsVisible(this._storageUseInvalidNodes, !valid);
this._setElementsVisible(this._storageUseExhaustWarnNodes, storageIsLow);
} finally {
this._isUpdating = false;
}
Expand Down
6 changes: 6 additions & 0 deletions ext/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ <h1>Yomitan Settings</h1>
</span>
<span class="storage-use-finite" hidden>
Yomitan is using approximately <span class="storage-usage">?</span> of <span class="storage-quota">?</span>.
<div class="storage-exhaustion-alert warning-text margin-above">
<div>
<strong>Your system is running low on storage space.</strong><br>
Importing dictionaries may fail.
</div>
</div>
</span>
<span class="storage-use-infinite" hidden>
Yomitan is permitted unlimited storage.
Expand Down

0 comments on commit 1452569

Please sign in to comment.