Pārlūkot izejas kodu

Update AppCache in background when toggling light and enabling docs inline

Thibaut 10 gadi atpakaļ
vecāks
revīzija
8de2dd607b

+ 1 - 0
assets/javascripts/app/app.coffee

@@ -102,6 +102,7 @@
       @initDoc(doc)
       @settings.setDocs(doc.slug for doc in @docs.all())
       _onSuccess()
+      @appCache?.updateInBackground()
       return
 
     doc.load onSuccess, onError, writeCache: true

+ 8 - 3
assets/javascripts/app/appcache.coffee

@@ -14,13 +14,18 @@ class app.AppCache
     $.on @cache, 'updateready', @onUpdateReady
 
   update: ->
+    @notifyUpdate = true
+    try @cache.update() catch
+    return
+
+  updateInBackground: ->
+    @notifyUpdate = false
     try @cache.update() catch
     return
 
   reload: ->
-    @reloading = true
     $.on @cache, 'updateready noupdate error', -> window.location = '/'
-    @update()
+    @updateInBackground()
     return
 
   onProgress: (event) =>
@@ -28,5 +33,5 @@ class app.AppCache
     return
 
   onUpdateReady: =>
-    @trigger 'updateready' unless @reloading
+    @trigger 'updateready' if @notifyUpdate
     return

+ 1 - 0
assets/javascripts/views/layout/document.coffee

@@ -23,6 +23,7 @@ class app.views.Document extends app.View
     css.setAttribute('data-alt', css.getAttribute('href'))
     css.setAttribute('href', alt)
     app.settings.setDark(alt.indexOf('dark') > 0)
+    app.appCache?.updateInBackground()
     return
 
   setTitle: (title) ->