2013-10-24 20:25:52 +02:00
|
|
|
class app.AppCache
|
|
|
|
$.extend @prototype, Events
|
|
|
|
|
|
|
|
@isEnabled: ->
|
|
|
|
try
|
|
|
|
applicationCache and applicationCache.status isnt applicationCache.UNCACHED
|
|
|
|
catch
|
|
|
|
|
|
|
|
constructor: ->
|
|
|
|
@cache = applicationCache
|
|
|
|
@onUpdateReady() if @cache.status is @cache.UPDATEREADY
|
|
|
|
|
|
|
|
$.on @cache, 'progress', @onProgress
|
|
|
|
$.on @cache, 'updateready', @onUpdateReady
|
|
|
|
|
|
|
|
@lastCheck = Date.now()
|
|
|
|
$.on window, 'focus', @checkForUpdate
|
|
|
|
|
|
|
|
update: ->
|
|
|
|
try @cache.update() catch
|
|
|
|
return
|
|
|
|
|
|
|
|
reload: ->
|
|
|
|
@reloading = true
|
|
|
|
$.on @cache, 'updateready noupdate error', -> window.location = '/'
|
|
|
|
@update()
|
|
|
|
return
|
|
|
|
|
|
|
|
checkForUpdate: =>
|
|
|
|
if Date.now() - @lastCheck > 86400e3
|
|
|
|
@lastCheck = Date.now()
|
|
|
|
@update()
|
|
|
|
return
|
|
|
|
|
|
|
|
onProgress: (event) =>
|
|
|
|
@trigger 'progress', event
|
|
|
|
return
|
|
|
|
|
|
|
|
onUpdateReady: =>
|
2014-11-23 16:51:47 +01:00
|
|
|
new app.views.Notif 'UpdateReady', autoHide: null unless @reloading
|
2013-10-24 20:25:52 +02:00
|
|
|
@trigger 'updateready'
|
|
|
|
return
|