From b0fc681480da40ec0bdb43773275ef7181c78cf1 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 18 Apr 2017 02:18:14 +0100 Subject: Check whether chrome.storage.sync is enabled, fall back to .local if not --- lib/settings.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/settings.coffee b/lib/settings.coffee index 51bb8bc4..51f6b504 100644 --- a/lib/settings.coffee +++ b/lib/settings.coffee @@ -27,6 +27,14 @@ Settings = @cache = if Utils.isBackgroundPage() then localStorage else extend {}, localStorage @runOnLoadedCallbacks() + # Test chrome.storage.sync to see if it is enabled. + # NOTE(mrmr1993, 2017-04-18): currently the API is defined in FF, but it is disabled behind a flag in + # about:config. Every use sets chrome.runtime.lastError, so we use that to check whether we can use it. + chrome.storage.sync.get null, => + if chrome.runtime.lastError + storageArea = "local" + @storage = chrome.storage[storageArea] + chrome.storage.local.get null, (localItems) => localItems = {} if chrome.runtime.lastError @storage.get null, (syncedItems) => -- cgit v1.2.3