mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Protection against possible local storage write errors.
This commit is contained in:
parent
64654257a1
commit
406175a410
1 changed files with 14 additions and 6 deletions
|
@ -4,14 +4,18 @@ define [
|
||||||
CACHE_KEY = "countlyEvents"
|
CACHE_KEY = "countlyEvents"
|
||||||
|
|
||||||
_getEventCache = () ->
|
_getEventCache = () ->
|
||||||
eventCache = window.localStorage.getItem CACHE_KEY
|
eventCacheStr = window.localStorage.getItem CACHE_KEY
|
||||||
|
|
||||||
# Initialize as an empy object if the event cache is still empty.
|
# Initialize as an empy object if the event cache is still empty.
|
||||||
if !eventCache?
|
if !eventCacheStr?
|
||||||
window.localStorage.setItem(CACHE_KEY, "{}")
|
eventCacheStr = "{}"
|
||||||
eventCache = window.localStorage.getItem CACHE_KEY
|
|
||||||
|
|
||||||
return JSON.parse eventCache
|
# Errors writing to localStorage may happen when quota is full or
|
||||||
|
# browser is in incognito mode. We'll return an empty object, anyway.
|
||||||
|
try
|
||||||
|
window.localStorage.setItem CACHE_KEY, eventCacheStr
|
||||||
|
|
||||||
|
return JSON.parse eventCacheStr
|
||||||
|
|
||||||
_eventInCache = (key) ->
|
_eventInCache = (key) ->
|
||||||
curCache = _getEventCache()
|
curCache = _getEventCache()
|
||||||
|
@ -25,7 +29,11 @@ define [
|
||||||
curCache = _getEventCache()
|
curCache = _getEventCache()
|
||||||
curCache[key] = true
|
curCache[key] = true
|
||||||
curCacheAsStr = JSON.stringify curCache
|
curCacheAsStr = JSON.stringify curCache
|
||||||
window.localStorage.setItem CACHE_KEY, curCacheAsStr
|
|
||||||
|
# Protection against issues mentioned above.
|
||||||
|
try
|
||||||
|
window.localStorage.setItem CACHE_KEY, curCacheAsStr
|
||||||
|
|
||||||
|
|
||||||
App.factory "event_tracking", ->
|
App.factory "event_tracking", ->
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue