2017-07-19 23:05:08 +02:00
|
|
|
const { remote } = require("electron");
|
|
|
|
|
2017-03-15 04:05:07 +01:00
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.getItem(). Parses JSON and returns undefined if the value
|
|
|
|
* is not set yet.
|
|
|
|
*/
|
2017-06-06 06:21:55 +02:00
|
|
|
export function getLocal(key, fallback = undefined) {
|
2017-06-20 14:08:52 +02:00
|
|
|
const itemRaw = localStorage.getItem(key);
|
|
|
|
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
2017-03-15 04:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.setItem(). Converts value to JSON.
|
|
|
|
*/
|
|
|
|
export function setLocal(key, value) {
|
2017-06-20 14:08:52 +02:00
|
|
|
localStorage.setItem(key, JSON.stringify(value));
|
2017-04-10 14:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.getItem(). Parses JSON and returns undefined if the value
|
|
|
|
* is not set yet.
|
|
|
|
*/
|
2017-06-06 06:21:55 +02:00
|
|
|
export function getSession(key, fallback = undefined) {
|
2017-06-20 14:08:52 +02:00
|
|
|
const itemRaw = sessionStorage.getItem(key);
|
|
|
|
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
2017-04-10 14:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.setItem(). Converts value to JSON.
|
|
|
|
*/
|
|
|
|
export function setSession(key, value) {
|
2017-06-20 14:08:52 +02:00
|
|
|
sessionStorage.setItem(key, JSON.stringify(value));
|
2017-06-06 06:21:55 +02:00
|
|
|
}
|