-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathupdate_checker.coffee
More file actions
39 lines (32 loc) · 939 Bytes
/
update_checker.coffee
File metadata and controls
39 lines (32 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class app.UpdateChecker
constructor: ->
@lastCheck = Date.now()
$.on window, 'focus', @onFocus
app.serviceWorker?.on 'updateready', @onUpdateReady
setTimeout @checkDocs, 0
check: ->
if app.serviceWorker
app.serviceWorker.update()
else
ajax
url: $('script[src*="application"]').getAttribute('src')
dataType: 'application/javascript'
error: (_, xhr) => @onUpdateReady() if xhr.status is 404
return
onUpdateReady: ->
new app.views.Notif 'UpdateReady', autoHide: null
return
checkDocs: =>
unless app.settings.get('manualUpdate')
app.docs.updateInBackground()
else
app.docs.checkForUpdates (i) => @onDocsUpdateReady() if i > 0
return
onDocsUpdateReady: ->
new app.views.Notif 'UpdateDocs', autoHide: null
return
onFocus: =>
if Date.now() - @lastCheck > 21600e3
@lastCheck = Date.now()
@check()
return