Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added chrome notification messages #180

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/userdata.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ var userInfo = {
userFollow: true,
gMapsAPIKey: "YOUR_API_KEY_HERE",
botPath: true,
actionsEnabled: false
actionsEnabled: false,
pushEnabled: true
};
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
</label>
</div>
<br>
</li>
<li>
Push notifications
<div class="switch">
<label>
Off
<input type="checkbox" id="pushOn">
<span class="lever"></span>
On
</label>
</div>
<br>
</li>
<li>
Logs
Expand Down
39 changes: 38 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ var mapView = {
$('#switchPan').prop('checked', self.settings.userFollow);
$('#switchZoom').prop('checked', self.settings.userZoom);
$('#strokeOn').prop('checked', self.settings.botPath);
$('#pushOn').prop('checked', self.settings.pushEnabled);

$('#pushOn').change(function() {
self.settings.pushEnabled = this.checked;
if (this.checked && Notification.permission !== "granted" ) {
Notification.requestPermission();
} else {
self.settings.pushEnabled = false;
}
});

$('#switchPan').change(function() {
if (this.checked) {
Expand Down Expand Up @@ -509,6 +519,7 @@ var mapView = {
self.log({
message: "[" + self.settings.users[user_index] + "] " + poke_name + " has been caught or fled"
});
self.notify( 'Pokemon status', poke_name + ' caught (or fled)' );
for (var key in user.catchables) {
user.catchables[key].setMap(null);
}
Expand Down Expand Up @@ -1018,7 +1029,33 @@ var mapView = {
}
}
return level;
}
},
notify: function(title, message) {
var self = this;
// Only show notification if enabled
if (self.settings.pushEnabled && Notification.permission == "granted") {

// Bind notification
self.settings.notification = new Notification(title, {
body: message
});

// Bind onclick event
self.settings.notification.onclick(function() {
window.open(window.location.href);
});

} else {
console.log( 'Notification: ' + title + ' with message:"' + message + '" has not been send to the client.');
console.log( 'Reason: ' );
if( !self.settings.pushEnabled ) {
console.log( 'Push is not enabled' );
} else if (Notification.permission !== 'granted') {
console.log( 'Push is not permitted' );
}
}

}
};

if (!String.prototype.format) {
Expand Down