mirror of
https://github.com/khairul169/honey.git
synced 2025-04-28 14:59:32 +07:00
44 lines
782 B
JavaScript
44 lines
782 B
JavaScript
export default class Config {
|
|
constructor(config) {
|
|
this.config = config
|
|
|
|
// localStorage availability check
|
|
try {
|
|
window.localStorage
|
|
this.storageAvailable = true
|
|
}
|
|
catch (e) {
|
|
this.storageAvailable = false
|
|
}
|
|
}
|
|
|
|
get(key) {
|
|
let value = this.config["ui"][key]
|
|
|
|
if (this.storageAvailable) {
|
|
let type = typeof(value)
|
|
let stored_value = window.localStorage.getItem(key)
|
|
|
|
if (stored_value != null) {
|
|
value = stored_value
|
|
if (type == "number") value = Number(value)
|
|
else if (type == "boolean") value = value == "true"
|
|
}
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
set(key, value) {
|
|
this.config["ui"][key] = value
|
|
|
|
if (this.storageAvailable) {
|
|
window.localStorage.setItem(key, value)
|
|
}
|
|
}
|
|
|
|
getServices() {
|
|
return this.config["services"]
|
|
}
|
|
}
|