Commit c078db6b9e487c070dca1853f3daf7ead2a72717

Authored by Chung Wang
1 parent 5a0a5435a4

add check for serviceworker and check button

Showing 2 changed files with 14 additions and 3 deletions Inline Diff

scripts/SettingsController.js View file @ c078db6
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");
navigator.serviceWorker.register('scripts/service-worker.js').then( 31 31 if ('serviceWorker' in navigator) {
32 navigator.serviceWorker.register('scripts/service-worker.js').then(
function(serviceWorkerRegistration) { 32 33 function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe().then( 33 34 serviceWorkerRegistration.pushManager.subscribe().then(
function(pushSubscription) { 34 35 function(pushSubscription) {
console.log('sub id: ', pushSubscription.subscriptionId); 35 36 console.log('sub id: ', pushSubscription.subscriptionId);
console.log('endpoint: ', pushSubscription.endpoint); 36 37 console.log('endpoint: ', pushSubscription.endpoint);
// The push subscription details needed by the application 37 38 // The push subscription details needed by the application
// server are now available, and can be sent to it using, 38 39 // server are now available, and can be sent to it using,
// for example, an XMLHttpRequest. 39 40 // for example, an XMLHttpRequest.
}, function(error) { 40 41 }, function(error) {
// During development it often helps to log errors to the 41 42 // During development it often helps to log errors to the
// console. In a production environment it might make sense to 42 43 // console. In a production environment it might make sense to
// also report information about errors back to the 43 44 // also report information about errors back to the
// application server. 44 45 // application server.
console.log('sub error: ', error); 45 46 console.log('sub error: ', error);
} 46 47 }
); 47 48 );
}); 48 49 });
50
51 } else {
52 console.log('Service workers aren\'t supported in this browser.');
templates/settings.html View file @ c078db6
<div class="card" id="resetPasswordForm"> 1 1 <div class="card" id="resetPasswordForm">
2 2
<input type="checkbox" class="js-checkbox" name="notifbox" value="toggle notifs">Check this to enable notifications<br> 3 3 <!--
4 class="js-checkbox" name="notifbox" value="toggle notifs"> -->
5 <form action="#">
6 <input type="checkbox" id = "notifbox" class="js-checkbox" />
7 <label for="notifbox">Check this to enable notifications</label>
8 </form>
4 9
<h2>Change Password</h2> 5 10 <h2>Change Password</h2>
6 11
<div class="row"> 7 12 <div class="row">
<form class="col s12"> 8 13 <form class="col s12">
9
10 14
<div class="row"> 11 15 <div class="row">
<div class="input-field col s12"> 12 16 <div class="input-field col s12">
<input id="password" type="password" ng-model="oldPassword" class="validate"> 13 17 <input id="password" type="password" ng-model="oldPassword" class="validate">
<label for="password">Old Password</label> 14 18 <label for="password">Old Password</label>
</div> 15 19 </div>
</div> 16 20 </div>
17 21
<div class="row"> 18 22 <div class="row">
<div class="input-field col s12"> 19 23 <div class="input-field col s12">
<input id="password" type="password" ng-model="newPassword" class="validate"> 20 24 <input id="password" type="password" ng-model="newPassword" class="validate">
<label for="password">New Password</label> 21 25 <label for="password">New Password</label>
</div> 22 26 </div>
</div> 23 27 </div>
24 28
<div class="row"> 25 29 <div class="row">
<div class="input-field col s12"> 26 30 <div class="input-field col s12">
<input id="password" type="password" ng-model="confirmedNewPassword" class="validate"> 27 31 <input id="password" type="password" ng-model="confirmedNewPassword" class="validate">
<label for="password">Confirm New Password</label> 28 32 <label for="password">Confirm New Password</label>
</div> 29 33 </div>