Skip to content

Commit

Permalink
conditionally use extension store if supported or enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
heyellieday committed Jan 3, 2018
1 parent 7184db7 commit 3c6a5b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ async function loadStateFromPersistence () {
// read from disk
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
// fetch from extension store and merge in data
const extensionData = await extensionStore.fetch() // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
versionedData = { ...versionedData, ...extensionData }

if (extensionStore.isSupported && extensionStore.isEnabled) {
const extensionData = await extensionStore.fetch() // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
versionedData = { ...versionedData, ...extensionData }
}

// migrate data
versionedData = await migrator.migrateData(versionedData)
// write to disk
Expand Down Expand Up @@ -92,7 +96,9 @@ function setupController (initState) {
}

function syncDataWithExtension(state) {
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
if (extensionStore.isSupported && extensionStore.isEnabled) {
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
}
return state
}

Expand Down
4 changes: 4 additions & 0 deletions app/scripts/lib/extension-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const handleDisabledSyncAndResolve = (resolve, toResolve) => {
}

module.exports = class ExtensionStore {
constructor() {
this.isSupported = !!(extension.storage.sync)
this.isEnabled = true // TODO: get value from user settings
}
async fetch() {
return new Promise((resolve) => {
extension.storage.sync.get(KEYS_TO_SYNC, (data) => {
Expand Down

0 comments on commit 3c6a5b1

Please sign in to comment.