Unified · Split
| @@ -96,14 +96,7 @@ · 95 unmodified lines | ||
| 96 | 96 | new app.views.Notif 'Share', autoHide: null if visitCount is 5 |
| 97 | 97 | new app.views.Notif 'Thanks', autoHide: null if visitCount is 10 |
| 98 | 98 | 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() | |
| 107 | 100 | |
| 108 | 101 | reload: -> |
| 109 | 102 | @docs.clearCache() |
| @@ -13,9 +13,6 @@ class app.AppCache · 12 unmodified lines | ||
| 13 | 13 | $.on @cache, 'progress', @onProgress |
| 14 | 14 | $.on @cache, 'updateready', @onUpdateReady |
| 15 | 15 | |
| 16 | − @lastCheck = Date.now() | |
| 17 | − $.on window, 'focus', @checkForUpdate | |
| 18 | − | |
| 19 | 16 | update: -> |
| 20 | 17 | try @cache.update() catch |
| 21 | 18 | return |
| @@ -26,17 +23,10 @@ class app.AppCache · 4 unmodified lines | ||
| 26 | 23 | @update() |
| 27 | 24 | return |
| 28 | 25 | |
| 29 | − checkForUpdate: => | |
| 30 | − if Date.now() - @lastCheck > 86400e3 | |
| 31 | − @lastCheck = Date.now() | |
| 32 | − @update() | |
| 33 | − return | |
| 34 | − | |
| 35 | 26 | onProgress: (event) => |
| 36 | 27 | @trigger 'progress', event |
| 37 | 28 | return |
| 38 | 29 | |
| 39 | 30 | onUpdateReady: => |
| 40 | − new app.views.Notif 'UpdateReady', autoHide: null unless @reloading | |
| 41 | − @trigger 'updateready' | |
| 31 | + @trigger 'updateready' unless @reloading | |
| 42 | 32 | return |
| @@ -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 | |