aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/persistent-storage-controller.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/pages/settings/persistent-storage-controller.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/pages/settings/persistent-storage-controller.js')
-rw-r--r--ext/js/pages/settings/persistent-storage-controller.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/ext/js/pages/settings/persistent-storage-controller.js b/ext/js/pages/settings/persistent-storage-controller.js
index aa060c14..e85bfc6b 100644
--- a/ext/js/pages/settings/persistent-storage-controller.js
+++ b/ext/js/pages/settings/persistent-storage-controller.js
@@ -21,22 +21,27 @@ import {yomitan} from '../../yomitan.js';
export class PersistentStorageController {
constructor() {
- this._persistentStorageCheckbox = false;
+ /** @type {?HTMLInputElement} */
+ this._persistentStorageCheckbox = null;
}
+ /** */
async prepare() {
- this._persistentStorageCheckbox = document.querySelector('#storage-persistent-checkbox');
+ this._persistentStorageCheckbox = /** @type {HTMLInputElement} */ (document.querySelector('#storage-persistent-checkbox'));
this._persistentStorageCheckbox.addEventListener('change', this._onPersistentStorageCheckboxChange.bind(this), false);
if (!this._isPersistentStorageSupported()) { return; }
- const info = document.querySelector('#storage-persistent-info');
+ const info = /** @type {?HTMLElement} */ (document.querySelector('#storage-persistent-info'));
if (info !== null) { info.hidden = false; }
const isStoragePeristent = await this.isStoragePeristent();
this._updateCheckbox(isStoragePeristent);
}
+ /**
+ * @returns {Promise<boolean>}
+ */
async isStoragePeristent() {
try {
return await navigator.storage.persisted();
@@ -48,8 +53,11 @@ export class PersistentStorageController {
// Private
+ /**
+ * @param {Event} e
+ */
_onPersistentStorageCheckboxChange(e) {
- const node = e.currentTarget;
+ const node = /** @type {HTMLInputElement} */ (e.currentTarget);
if (node.checked) {
node.checked = false;
this._attemptPersistStorage();
@@ -58,6 +66,7 @@ export class PersistentStorageController {
}
}
+ /** */
async _attemptPersistStorage() {
let isStoragePeristent = false;
try {
@@ -68,18 +77,24 @@ export class PersistentStorageController {
this._updateCheckbox(isStoragePeristent);
- const node = document.querySelector('#storage-persistent-fail-warning');
+ const node = /** @type {?HTMLElement} */ (document.querySelector('#storage-persistent-fail-warning'));
if (node !== null) { node.hidden = isStoragePeristent; }
yomitan.trigger('storageChanged');
}
+ /**
+ * @returns {boolean}
+ */
_isPersistentStorageSupported() {
return isObject(navigator.storage) && typeof navigator.storage.persist === 'function';
}
+ /**
+ * @param {boolean} isStoragePeristent
+ */
_updateCheckbox(isStoragePeristent) {
- this._persistentStorageCheckbox.checked = isStoragePeristent;
- this._persistentStorageCheckbox.readOnly = isStoragePeristent;
+ /** @type {HTMLInputElement} */ (this._persistentStorageCheckbox).checked = isStoragePeristent;
+ /** @type {HTMLInputElement} */ (this._persistentStorageCheckbox).readOnly = isStoragePeristent;
}
}