mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Handle cases where sync storage is not available. Fix #406.
This commit is contained in:
parent
4ebcf74828
commit
eb8c0b99d8
@ -138,11 +138,12 @@ actionForUrl = (url) ->
|
|||||||
storage = new OmegaTargetCurrent.Storage(chrome.storage.local, 'local')
|
storage = new OmegaTargetCurrent.Storage(chrome.storage.local, 'local')
|
||||||
state = new OmegaTargetCurrent.BrowserStorage(localStorage, 'omega.local.')
|
state = new OmegaTargetCurrent.BrowserStorage(localStorage, 'omega.local.')
|
||||||
|
|
||||||
syncStorage = new OmegaTargetCurrent.Storage(chrome.storage.sync, 'sync')
|
if chrome.storage.sync
|
||||||
sync = new OmegaTargetCurrent.OptionsSync(syncStorage)
|
syncStorage = new OmegaTargetCurrent.Storage(chrome.storage.sync, 'sync')
|
||||||
if localStorage['omega.local.syncOptions'] != '"sync"'
|
sync = new OmegaTargetCurrent.OptionsSync(syncStorage)
|
||||||
sync.enabled = false
|
if localStorage['omega.local.syncOptions'] != '"sync"'
|
||||||
sync.transformValue = OmegaTargetCurrent.Options.transformValueForSync
|
sync.enabled = false
|
||||||
|
sync.transformValue = OmegaTargetCurrent.Options.transformValueForSync
|
||||||
|
|
||||||
options = new OmegaTargetCurrent.Options(null, storage, state, Log, sync)
|
options = new OmegaTargetCurrent.Options(null, storage, state, Log, sync)
|
||||||
options.externalApi = new OmegaTargetCurrent.ExternalApi(options)
|
options.externalApi = new OmegaTargetCurrent.ExternalApi(options)
|
||||||
|
@ -24,6 +24,10 @@ class ChromeStorage extends OmegaTarget.Storage
|
|||||||
err = new OmegaTarget.Storage.RateLimitExceededError()
|
err = new OmegaTarget.Storage.RateLimitExceededError()
|
||||||
err.perMinute = true
|
err.perMinute = true
|
||||||
err.sustained = 10
|
err.sustained = 10
|
||||||
|
else if err.message.indexOf('is not available') >= 0
|
||||||
|
# This could happen if the storage area is not available. For example,
|
||||||
|
# some Chromium-based browsers disable access to the sync storage.
|
||||||
|
err = new OmegaTarget.Storage.StorageUnavailableError()
|
||||||
|
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
|
|
||||||
|
@ -89,7 +89,14 @@ class Options
|
|||||||
else
|
else
|
||||||
@_state.set({'syncOptions': 'sync'})
|
@_state.set({'syncOptions': 'sync'})
|
||||||
@_syncWatchStop = @sync.watchAndPull(@_storage)
|
@_syncWatchStop = @sync.watchAndPull(@_storage)
|
||||||
@sync.copyTo(@_storage).then =>
|
@sync.copyTo(@_storage).catch(Storage.StorageUnavailableError, =>
|
||||||
|
console.error('Warning: Sync storage is not available in this ' +
|
||||||
|
'browser! Disabling options sync.')
|
||||||
|
@_syncWatchStop?()
|
||||||
|
@_syncWatchStop = null
|
||||||
|
@sync = null
|
||||||
|
@_state.set({'syncOptions': 'unsupported'})
|
||||||
|
).then =>
|
||||||
@_storage.get(null)
|
@_storage.get(null)
|
||||||
|
|
||||||
@optionsLoaded = loadRaw.then((options) =>
|
@optionsLoaded = loadRaw.then((options) =>
|
||||||
|
@ -19,6 +19,17 @@ class Storage
|
|||||||
class QuotaExceededError extends Error
|
class QuotaExceededError extends Error
|
||||||
constructor: -> super
|
constructor: -> super
|
||||||
|
|
||||||
|
###*
|
||||||
|
# If this storage is not available for some reason, all operations should
|
||||||
|
# reject with an instance of StorageUnavailableError, when implemented in
|
||||||
|
# derived classes of Storage.
|
||||||
|
# This error is considered fatal and unrecoverable in the current environment.
|
||||||
|
# Further access to this storage should be avoided until restart.
|
||||||
|
###
|
||||||
|
@StorageUnavailableError:
|
||||||
|
class StorageUnavailableError extends Error
|
||||||
|
constructor: -> super
|
||||||
|
|
||||||
###*
|
###*
|
||||||
# A set of operations to be performed on a Storage.
|
# A set of operations to be performed on a Storage.
|
||||||
# @typedef WriteOperations
|
# @typedef WriteOperations
|
||||||
|
Loading…
Reference in New Issue
Block a user