diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee index ad0772f6..ec56e021 100644 --- a/assets/javascripts/app/app.coffee +++ b/assets/javascripts/app/app.coffee @@ -99,8 +99,11 @@ @checkForDocUpdates() checkForDocUpdates: -> - @docs.checkForUpdates (i) -> - new app.views.Notif 'UpdateDocs', autoHide: null if i > 0 + if @settings.get('autoUpdate') + @docs.updateInBackground() + else + @docs.checkForUpdates (i) -> + new app.views.Notif 'UpdateDocs', autoHide: null if i > 0 reload: -> @docs.clearCache() diff --git a/assets/javascripts/app/settings.coffee b/assets/javascripts/app/settings.coffee index e1552de5..46061040 100644 --- a/assets/javascripts/app/settings.coffee +++ b/assets/javascripts/app/settings.coffee @@ -7,6 +7,7 @@ class app.Settings hideDisabled: false hideIntro: false news: 0 + autoUpdate: true constructor: (@store) -> @create() unless @settings = @store.get(SETTINGS_KEY) diff --git a/assets/javascripts/collections/docs.coffee b/assets/javascripts/collections/docs.coffee index 1a69ac85..30001566 100644 --- a/assets/javascripts/collections/docs.coffee +++ b/assets/javascripts/collections/docs.coffee @@ -59,7 +59,16 @@ class app.collections.Docs extends app.Collection @getInstallStatuses (statuses) => i = 0 if statuses - i += 1 for slug, status of statuses when status.installed and @findBy('slug', slug).mtime isnt status.mtime + i += 1 for slug, status of statuses when @findBy('slug', slug).isOutdated(status) callback(i) return return + + updateInBackground: -> + @getInstallStatuses (statuses) => + return unless statuses + for slug, status of statuses + doc = @findBy 'slug', slug + doc.install($.noop, $.noop) if doc.isOutdated(status) + return + return diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index 44ce1ff2..13995a5a 100644 --- a/assets/javascripts/models/doc.coffee +++ b/assets/javascripts/models/doc.coffee @@ -130,3 +130,6 @@ class app.models.Doc extends app.Model app.db.version @, (value) -> callback installed: !!value, mtime: value return + + isOutdated: (status) -> + status.installed and @mtime isnt status.mtime diff --git a/assets/javascripts/templates/pages/offline_tmpl.coffee b/assets/javascripts/templates/pages/offline_tmpl.coffee index c8bfb376..4b993a76 100644 --- a/assets/javascripts/templates/pages/offline_tmpl.coffee +++ b/assets/javascripts/templates/pages/offline_tmpl.coffee @@ -5,6 +5,10 @@ app.templates.offlinePage = (docs) -> """
+