mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-05 06:22:52 +08:00
Update Client.js
This change made on mobile as test.
This commit is contained in:
parent
88704b5e12
commit
31d9ea53b9
1 changed files with 18 additions and 16 deletions
|
@ -1,6 +1,14 @@
|
||||||
import { CLIENT_SIDE_STORAGE_INDEX_NAME } from 'Common/Consts';
|
import { CLIENT_SIDE_STORAGE_INDEX_NAME } from 'Common/Consts';
|
||||||
|
|
||||||
const storage = localStorage;
|
const storage = localStorage,
|
||||||
|
getStorage = () => {
|
||||||
|
try {
|
||||||
|
const value = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null;
|
||||||
|
return null == value ? null : JSON.parse(value);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
|
@ -8,20 +16,15 @@ const storage = localStorage;
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function set(key, data) {
|
export function set(key, data) {
|
||||||
let storageResult = null;
|
const storageResult = getStorage() || {};
|
||||||
try {
|
storageResult['p' + key] = data;
|
||||||
const storageValue = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null;
|
|
||||||
storageResult = null === storageValue ? null : JSON.parse(storageValue);
|
|
||||||
} catch (e) {} // eslint-disable-line no-empty
|
|
||||||
|
|
||||||
(storageResult || (storageResult = {}))['p' + key] = data;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storage.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult));
|
storage.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult));
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {} // eslint-disable-line no-empty
|
} catch (e) {
|
||||||
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,11 +34,10 @@ export function set(key, data) {
|
||||||
export function get(key) {
|
export function get(key) {
|
||||||
try {
|
try {
|
||||||
key = 'p' + key;
|
key = 'p' + key;
|
||||||
const storageValue = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null,
|
const storageResult = getStorage();
|
||||||
storageResult = null === storageValue ? null : JSON.parse(storageValue);
|
|
||||||
|
|
||||||
return storageResult && null != storageResult[key] ? storageResult[key] : null;
|
return storageResult && null != storageResult[key] ? storageResult[key] : null;
|
||||||
} catch (e) {} // eslint-disable-line no-empty
|
} catch (e) {
|
||||||
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue