From 9dc99bd8ea8957a85f917aab7f4e7534731908f9 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sun, 8 Feb 2015 11:43:48 -0500 Subject: [PATCH] Detect and recover from IndexedDB QuotaExceededError Fixes #154 --- assets/javascripts/app/app.coffee | 4 ++++ assets/javascripts/app/db.coffee | 13 ++++++++++--- assets/javascripts/templates/notif_tmpl.coffee | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee index 6bb71224..2ccd0b87 100644 --- a/assets/javascripts/app/app.coffee +++ b/assets/javascripts/app/app.coffee @@ -132,6 +132,10 @@ @hideLoading() return + onQuotaExceeded: -> + new app.views.Notif 'QuotaExceeded', autoHide: null + Raven.captureMessage 'QuotaExceededError' + onWindowError: (args...) -> if @isInjectionError args... @onInjectionError() diff --git a/assets/javascripts/app/db.coffee b/assets/javascripts/app/db.coffee index 6aa8f461..e6c0c7f1 100644 --- a/assets/javascripts/app/db.coffee +++ b/assets/javascripts/app/db.coffee @@ -8,7 +8,7 @@ class app.DB db: (fn) -> return fn() unless @useIndexedDB - @callbacks.push(fn) + @callbacks.push(fn) if fn return if @open try @@ -39,8 +39,15 @@ class app.DB onOpenError: (event) => event?.preventDefault() - @useIndexedDB = @open = false - @runCallbacks() + @open = false + + if event?.target?.error?.name is 'QuotaExceededError' + @reset() + @db() + app.onQuotaExceeded() + else + @useIndexedDB = false + @runCallbacks() return runCallbacks: (db) -> diff --git a/assets/javascripts/templates/notif_tmpl.coffee b/assets/javascripts/templates/notif_tmpl.coffee index 7de9f521..d2ce3836 100644 --- a/assets/javascripts/templates/notif_tmpl.coffee +++ b/assets/javascripts/templates/notif_tmpl.coffee @@ -15,6 +15,10 @@ app.templates.notifError = -> resetting the app.
You can also report this issue on GitHub. """ +app.templates.notifQuotaExceeded = -> + textNotif """ Oops, the offline database has exceeded its size limitation. """, + """ Unfortunately this quota can't be detected programmatically, and the database can't be opened while over the quota, so it had to be reset. """ + app.templates.notifInvalidLocation = -> textNotif """ DevDocs must be loaded from #{app.config.production_host} """, """ Otherwise things are likely to break. """