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
9696 new app.views.Notif 'Share', autoHide: null if visitCount is 5
9797 new app.views.Notif 'Thanks', autoHide: null if visitCount is 10
9898 new app.views.News()
99− @checkForDocUpdates()
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
99+ @updateChecker = new app.UpdateChecker()
107100
108101 reload: ->
109102 @docs.clearCache()
assets/javascripts/app/appcache.coffee+1−11
@@ -13,9 +13,6 @@ class app.AppCache · 12 unmodified lines
1313 $.on @cache, 'progress', @onProgress
1414 $.on @cache, 'updateready', @onUpdateReady
1515
16− @lastCheck = Date.now()
17− $.on window, 'focus', @checkForUpdate
18−
1916 update: ->
2017 try @cache.update() catch
2118 return
@@ -26,17 +23,10 @@ class app.AppCache · 4 unmodified lines
2623 @update()
2724 return
2825
29− checkForUpdate: =>
30− if Date.now() - @lastCheck > 86400e3
31− @lastCheck = Date.now()
32− @update()
33− return
34−
3526 onProgress: (event) =>
3627 @trigger 'progress', event
3728 return
3829
3930 onUpdateReady: =>
40− new app.views.Notif 'UpdateReady', autoHide: null unless @reloading
41− @trigger 'updateready'
31+ @trigger 'updateready' unless @reloading
4232 return
assets/javascripts/app/update_checker.coffee+39−0
@@ -0,0 +1,39 @@
1+class 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