From 4331e2c09f246c75d6ea391d317a22380bfb6534 Mon Sep 17 00:00:00 2001 From: Youri Date: Mon, 8 Aug 2016 14:34:16 +0200 Subject: [PATCH 1/3] Added chrome notification messages --- index.html | 12 ++++++++++++ js/main.js | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index fc04c61..3fd5f81 100644 --- a/index.html +++ b/index.html @@ -61,6 +61,18 @@
+ +
  • + Push notifications +
    + +
    +
  • Logs diff --git a/js/main.js b/js/main.js index 10ab923..7eae570 100644 --- a/js/main.js +++ b/js/main.js @@ -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) { @@ -470,6 +480,7 @@ var mapView = { message: "[" + self.settings.users[user_index] + "] " + poke_name + " appeared", color: "green-text" }); + self.notify( 'Pokemon status', poke_name + ' appeared' ); user.catchables[data.spawnpoint_id] = new google.maps.Marker({ map: self.map, position: { @@ -509,6 +520,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); } @@ -1018,7 +1030,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) { From c9ec4de843e0fbfdb29a45867119a31251d7e27c Mon Sep 17 00:00:00 2001 From: Youri vd Bogert Date: Mon, 8 Aug 2016 14:44:07 +0200 Subject: [PATCH 2/3] Added default configuration.. --- config/userdata.js.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/userdata.js.example b/config/userdata.js.example index c16c899..ffe60e1 100644 --- a/config/userdata.js.example +++ b/config/userdata.js.example @@ -7,5 +7,6 @@ var userInfo = { userFollow: true, gMapsAPIKey: "YOUR_API_KEY_HERE", botPath: true, - actionsEnabled: false + actionsEnabled: false, + pushEnabled: true }; From 7486d562f9527b19971e27f050f658a91e30974e Mon Sep 17 00:00:00 2001 From: Youri vd Bogert Date: Tue, 9 Aug 2016 09:32:07 +0200 Subject: [PATCH 3/3] Removed notify on spawn's Otherwise the notification's will continue to appear.. --- js/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/main.js b/js/main.js index 7eae570..2cb3a9e 100644 --- a/js/main.js +++ b/js/main.js @@ -480,7 +480,6 @@ var mapView = { message: "[" + self.settings.users[user_index] + "] " + poke_name + " appeared", color: "green-text" }); - self.notify( 'Pokemon status', poke_name + ' appeared' ); user.catchables[data.spawnpoint_id] = new google.maps.Marker({ map: self.map, position: {