Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created February 18, 2014 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/9069421 to your computer and use it in GitHub Desktop.
Save robwormald/9069421 to your computer and use it in GitHub Desktop.
app.factory('chromeAccountProxy',function(){
var _localAccounts = []
var _isLoggedIn = false;
function sendMessage(message){
chrome.extension.sendMessage(message)
}
function recieveMessage(message,sender,sendResponse){
// new account
if(message.action == 'account:add'){
_localAccounts.push(message.account)
}
if(message.action == 'account:update'){
//find obj in _localAccounts and update
}
}
function addAccount(accountDetails){
sendMessage({action : 'account:create', account : accountDetails})
}
//assume we're listening for changes to accounts}
chrome.extension.onMessage.addListener(recieveMessage)
return {
addAccountLocally : _addNewAccount,
allAccounts : _localAccounts
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment