From 510d5ab2cdba8a812e2bde097f013c7e80eaf55b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 12 Feb 2021 19:08:13 +0100 Subject: [PATCH] add bool settings type --- src/platform/web/dom/SettingsStorage.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/platform/web/dom/SettingsStorage.js b/src/platform/web/dom/SettingsStorage.js index 0b3e81a8..4e4c18c7 100644 --- a/src/platform/web/dom/SettingsStorage.js +++ b/src/platform/web/dom/SettingsStorage.js @@ -20,18 +20,34 @@ export class SettingsStorage { } async setInt(key, value) { - window.localStorage.setItem(`${this._prefix}${key}`, value); + this._set(key, value); } - async getInt(key) { + async getInt(key, defaultValue = 0) { const value = window.localStorage.getItem(`${this._prefix}${key}`); if (typeof value === "string") { return parseInt(value, 10); } - return; + return defaultValue; + } + + async setBool(key, value) { + this._set(key, value); + } + + async getBool(key, defaultValue = false) { + const value = window.localStorage.getItem(`${this._prefix}${key}`); + if (typeof value === "string") { + return value === "true"; + } + return defaultValue; } async remove(key) { window.localStorage.removeItem(`${this._prefix}${key}`); } + + async _set(key, value) { + window.localStorage.setItem(`${this._prefix}${key}`, value); + } }