aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/persistent-storage-controller.js
diff options
context:
space:
mode:
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;
}
}