Created
April 28, 2020 11:52
-
-
Save smolinari/178acaf780fc4436bbfe86de660e0e69 to your computer and use it in GitHub Desktop.
The Quasar Todo example browser extension background hook file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function attachBackgroundHooks (bridge, allActiveConnections) { | |
bridge.on('storage.get', event => { | |
const payload = event.data | |
if (payload.key === null) { | |
chrome.storage.local.get(null, r => { | |
const result = [] | |
// Group the items up into an array to take advantage of the bridge's chunk splitting. | |
for (const itemKey in r) { | |
result.push(r[itemKey]) | |
} | |
bridge.send(event.eventResponseKey, result) | |
}) | |
} else { | |
chrome.storage.local.get([payload.key], r => { | |
bridge.send(event.eventResponseKey, r[payload.key]) | |
}) | |
} | |
}) | |
bridge.on('storage.set', event => { | |
const payload = event.data | |
chrome.storage.local.set({ [payload.key]: payload.data }, () => { | |
bridge.send(event.eventResponseKey, payload.data) | |
}) | |
}) | |
bridge.on('storage.remove', event => { | |
console.log('deleting2') | |
const payload = event.data | |
chrome.storage.local.remove(payload.key, () => { | |
bridge.send(event.eventResponseKey, payload.data) | |
}) | |
}) | |
chrome.browserAction.onClicked.addListener(() => { | |
bridge.send('bex.toggle.toolbar') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment