Commit 6ad6fec426cc9861372b77cf7797cfc8b96d6658

Authored by Chung Wang
1 parent 4ca44fc272

merge conclict

Showing 1 changed file with 1 additions and 5 deletions Inline Diff

scripts/SettingsController.js View file @ 6ad6fec
angular.module('flashy.SettingsController', ['ui.router']). 1 1 angular.module('flashy.SettingsController', ['ui.router']).
2 2
controller('SettingsController', function($scope, $http) { 3 3 controller('SettingsController', function($scope, $http) {
$scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) { 4 4 $scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) {
5 5
}; 6 6 };
console.log('checking to see if chrome'); 7 7 console.log('checking to see if chrome');
if (!chrome) { return; } 8 8 if (!chrome) { return; }
console.log('chrome'); 9 9 console.log('chrome');
$scope.registerCallback = function(registrationId) { 10 10 $scope.registerCallback = function(registrationId) {
if (chrome.runtime.lastError) { 11 11 if (chrome.runtime.lastError) {
console.log('Registration failed'); 12 12 console.log('Registration failed');
} 13 13 }
14 14
sendRegistrationId(registrationId, function(succeed) { 15 15 sendRegistrationId(registrationId, function(succeed) {
if (succeed) { 16 16 if (succeed) {
chrome.storage.local.set({registered: true}); 17 17 chrome.storage.local.set({registered: true});
} 18 18 }
}); 19 19 });
}; 20 20 };
21 21
function sendRegistrationId(registrationId, callback) { 22 22 function sendRegistrationId(registrationId, callback) {
console.log('registration id: ' + registrationId); 23 23 console.log('registration id: ' + registrationId);
$http.post('/api/subscribe/', JSON.stringify({ 24 24 $http.post('/api/subscribe/', JSON.stringify({
'registration_id': registrationId 25 25 'registration_id': registrationId
})); 26 26 }));
callback(true); 27 27 callback(true);
} 28 28 }
29 29
console.log("gonna try to launch service worker now"); 30 30 console.log("gonna try to launch service worker now");
if ('serviceWorker' in navigator) { 31 31 if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('scripts/service-worker.js').then( 32
33 32
console.log('gonna try to launch service worker now'); 34 33 console.log('gonna try to launch service worker now');
navigator.serviceWorker.register('scripts/service-worker.js').then( 35 34 navigator.serviceWorker.register('scripts/service-worker.js').then(
function(serviceWorkerRegistration) { 36 35 function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe().then( 37 36 serviceWorkerRegistration.pushManager.subscribe().then(
function(pushSubscription) { 38 37 function(pushSubscription) {
console.log('sub id: ', pushSubscription.subscriptionId); 39 38 console.log('sub id: ', pushSubscription.subscriptionId);
console.log('endpoint: ', pushSubscription.endpoint); 40 39 console.log('endpoint: ', pushSubscription.endpoint);
// The push subscription details needed by the application 41 40 // The push subscription details needed by the application
// server are now available, and can be sent to it using, 42 41 // server are now available, and can be sent to it using,
// for example, an XMLHttpRequest. 43 42 // for example, an XMLHttpRequest.
}, function(error) { 44 43 }, function(error) {
// During development it often helps to log errors to the 45 44 // During development it often helps to log errors to the
// console. In a production environment it might make sense to 46 45 // console. In a production environment it might make sense to
// also report information about errors back to the 47 46 // also report information about errors back to the
// application server. 48 47 // application server.
console.log('sub error: ', error); 49 48 console.log('sub error: ', error);
} 50 49 }
); 51 50 );
}); 52 51 });
53 52