Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created February 18, 2014 11:04
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/9068830 to your computer and use it in GitHub Desktop.
Save robwormald/9068830 to your computer and use it in GitHub Desktop.
app.factory('chromeAPI',function($rootScope){
//native API!
chrome.runtime.onMessage.addListener(function(message,sender,response){
$rootScope.broadcast('chrome:message',message,sender,response)
})
function authenticateViaGoogle(){
//native API!
chrome.identity.getAuthToken({interactive : true}, function(token){
$rootScope.$broadcast('chrome:authenticated',token)
})
}
return {
signIn : authenticateViaGoogle
}
}
app.controller('testCtrl',function(chromeAPI){
$scope.login = chromeAPI.login;
$scope.$on('chrome:authenticated',function(token){
console.log('got a token')
$state.go('home')
})
$scope.$on('chrome:message',function(message,sender,respond){
console.log('got a message from chrome')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment