mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
add bool settings type
This commit is contained in:
parent
704708bd6c
commit
510d5ab2cd
@ -20,18 +20,34 @@ export class SettingsStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setInt(key, value) {
|
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}`);
|
const value = window.localStorage.getItem(`${this._prefix}${key}`);
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
return parseInt(value, 10);
|
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) {
|
async remove(key) {
|
||||||
window.localStorage.removeItem(`${this._prefix}${key}`);
|
window.localStorage.removeItem(`${this._prefix}${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _set(key, value) {
|
||||||
|
window.localStorage.setItem(`${this._prefix}${key}`, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user