mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Improve web storage detection.
Possible fix for Safari private mode (#1092)
This commit is contained in:
parent
a2308e251b
commit
739ed215ea
2 changed files with 52 additions and 18 deletions
|
|
@ -5,7 +5,34 @@ import JSON from 'JSON';
|
|||
const STORAGE_KEY = '__rlA';
|
||||
const TIME_KEY = '__rlT';
|
||||
|
||||
const SESS_STORAGE = window.sessionStorage || null;
|
||||
/**
|
||||
* @param {string} storageName
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isStorageSupported(storageName)
|
||||
{
|
||||
if (storageName in window && window[storageName] && window[storageName].setItem)
|
||||
{
|
||||
const
|
||||
s = window[storageName],
|
||||
key = 'testLocalStorage_' + window.Math.random();
|
||||
|
||||
try
|
||||
{
|
||||
s.setItem(key, key);
|
||||
if (key === s.getItem(key))
|
||||
{
|
||||
s.removeItem(key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const SESS_STORAGE = isStorageSupported('sessionStorage') ? (window.sessionStorage || null) : null;
|
||||
const WIN_STORAGE = window.top || window || null;
|
||||
|
||||
const __get = (key) => {
|
||||
|
|
@ -93,6 +120,4 @@ export function checkTimestamp()
|
|||
}
|
||||
|
||||
// init section
|
||||
window.setInterval(() => {
|
||||
setTimestamp();
|
||||
}, 1000 * 60); // 1m
|
||||
window.setInterval(setTimestamp, 1000 * 60); // 1m
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue