2018-08-11 12:08:00 +00:00
|
|
|
// This is a simple localStorage wrapper because browser can throw errors
|
|
|
|
// in different situations, including:
|
|
|
|
// - Unable to store data if storage is full
|
|
|
|
// - Local storage is blocked if "third-party cookies and site data" is disabled
|
|
|
|
//
|
|
|
|
// For more details, see:
|
|
|
|
// https://stackoverflow.com/q/14555347/1935861
|
|
|
|
// https://github.com/thelounge/thelounge/issues/2699
|
|
|
|
// https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document
|
|
|
|
|
2019-11-16 17:24:03 +00:00
|
|
|
export default {
|
2022-06-19 00:25:21 +00:00
|
|
|
set(key: string, value: string) {
|
2017-04-22 13:03:00 +00:00
|
|
|
try {
|
|
|
|
window.localStorage.setItem(key, value);
|
|
|
|
} catch (e) {
|
2018-08-11 12:08:00 +00:00
|
|
|
//
|
2017-04-22 13:03:00 +00:00
|
|
|
}
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
get(key: string) {
|
2018-08-11 12:08:00 +00:00
|
|
|
try {
|
|
|
|
return window.localStorage.getItem(key);
|
|
|
|
} catch (e) {
|
|
|
|
// Return null as if data is not set
|
|
|
|
return null;
|
|
|
|
}
|
2017-04-22 13:03:00 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
remove(key: string) {
|
2018-08-11 12:08:00 +00:00
|
|
|
try {
|
|
|
|
window.localStorage.removeItem(key);
|
|
|
|
} catch (e) {
|
|
|
|
//
|
|
|
|
}
|
2018-03-20 04:52:58 +00:00
|
|
|
},
|
|
|
|
clear() {
|
2018-08-11 12:08:00 +00:00
|
|
|
try {
|
|
|
|
window.localStorage.clear();
|
|
|
|
} catch (e) {
|
|
|
|
//
|
|
|
|
}
|
2017-11-15 06:35:15 +00:00
|
|
|
},
|
2017-04-22 13:03:00 +00:00
|
|
|
};
|