History

Check for updates when AppCache is disabled

Thibaut committed 11 years ago

Commit a7d212d1 parent 977e9913 files · +41 −19Browse files

Unified · Split

3 files
  1. assets/javascripts/app/app.coffee +1 −8
  2. assets/javascripts/app/appcache.coffee +1 −11
  3. assets/javascripts/app/update_checker.coffee +39 −0
assets/javascripts/app/app.coffee+1−8
@@ -96,14 +96,7 @@ · 95 unmodified lines
96 new app.views.Notif 'Share', autoHide: null if visitCount is 596 new app.views.Notif 'Share', autoHide: null if visitCount is 5
97 new app.views.Notif 'Thanks', autoHide: null if visitCount is 1097 new app.views.Notif 'Thanks', autoHide: null if visitCount is 10
98 new app.views.News()98 new app.views.News()
99 @checkForDocUpdates()99 @updateChecker = new app.UpdateChecker()
100
101 checkForDocUpdates: ->
102 if @settings.get('autoUpdate')
103 @docs.updateInBackground()
104 else
105 @docs.checkForUpdates (i) ->
106 new app.views.Notif 'UpdateDocs', autoHide: null if i > 0
107 100
108 reload: ->101 reload: ->
109 @docs.clearCache()102 @docs.clearCache()
assets/javascripts/app/appcache.coffee+1−11
@@ -13,9 +13,6 @@ class app.AppCache · 12 unmodified lines
13 $.on @cache, 'progress', @onProgress13 $.on @cache, 'progress', @onProgress
14 $.on @cache, 'updateready', @onUpdateReady14 $.on @cache, 'updateready', @onUpdateReady
15 15
16 @lastCheck = Date.now()
17 $.on window, 'focus', @checkForUpdate
18
19 update: ->16 update: ->
20 try @cache.update() catch17 try @cache.update() catch
21 return18 return
@@ -26,17 +23,10 @@ class app.AppCache · 4 unmodified lines
26 @update()23 @update()
27 return24 return
28 25
29 checkForUpdate: =>
30 if Date.now() - @lastCheck > 86400e3
31 @lastCheck = Date.now()
32 @update()
33 return
34
35 onProgress: (event) =>26 onProgress: (event) =>
36 @trigger 'progress', event27 @trigger 'progress', event
37 return28 return
38 29
39 onUpdateReady: =>30 onUpdateReady: =>
40 new app.views.Notif 'UpdateReady', autoHide: null unless @reloading31 @trigger 'updateready' unless @reloading
41 @trigger 'updateready'
42 return32 return
assets/javascripts/app/update_checker.coffee+39−0
@@ -0,0 +1,39 @@
1class app.UpdateChecker
2 constructor: ->
3 @lastCheck = Date.now()
4
5 $.on window, 'focus', @checkForUpdate
6 app.appCache.on 'updateready', @onUpdateReady if app.appCache
7
8 @checkDocs()
9
10 check: ->
11 if app.appCache
12 app.appCache.update()
13 else
14 ajax
15 url: $('script[src*="application"]').getAttribute('src')
16 dataType: 'application/javascript'
17 error: (_, xhr) => @onUpdateReady() if xhr.status is 404
18 return
19
20 onUpdateReady: ->
21 new app.views.Notif 'UpdateReady', autoHide: null
22 return
23
24 checkDocs: ->
25 if app.settings.get('autoUpdate')
26 app.docs.updateInBackground()
27 else
28 app.docs.checkForUpdates (i) => @onDocsUpdateReady() if i > 0
29 return
30
31 onDocsUpdateReady: ->
32 new app.views.Notif 'UpdateDocs', autoHide: null
33 return
34
35 onFocus: =>
36 if Date.now() - @lastCheck > 21600e3
37 @lastCheck = Date.now()
38 @check()
39 return