Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Fix mobile notifications on mobile chrome (#88)
Browse files Browse the repository at this point in the history
* Fix mobile notifications on mobile chrome

* Fix various Pokemon Name in safe sprite sheet (#89)

* Fix various pokemon in Sprite sheet

* fix sizing of corrected sprites

* Added weather sprites

* Add option to link to Worldopole (#68)

* Enable Full Stats if $worldopoleURL is set

* update default config

* Update example.config.php

* Update default.php

* Update pre-index.php

* fix styling

* Update pre-index.php

* Update pre-index.php

* Improve min iv moving extra sql calc to PHP (#82)

* Improvements to MinIV Script to remove to calculations from SQL

* Fix Style CI Errors

* Simplifying MinIV/MinLVL Query even more to share pokemon exclude list.

* [fix] Spawnpoint Timers (#49)

* [fix] Spawnpoint Timers

* Travis

* Indentation

* That didnÃ't need changing.

* RM fix

* Show infoWindow on specific encounter when specified in querystring (#41)

* Added supporting code to show the info box for a specific encounter when specified in the url.

* Fixed eslint errors

* Fixed CI style errors

* Fixed eslint error

* Adapted to new server side filtering for monkey monocle

* Fixed merge conflict for develop

* Fix PHP error

* Fixed StyleCI errors

* Fixed Travis

* Potential fix to make enc_id play nice with big karp/tiny rat

* Added fix for karp/rats on pgsql

* Fix for certain PgSQL installs not liking || and &&

* Added support for encId on other forks/scanners

Also a few more PgSQL compatibility fixes

* StyleCI fixes

* Fixes for encounter issues with miniv

* Fix for Data Performance on Large Databases with Encounter Id (#84)

* start to encounter fixes

* Potential Fix for hidden Mons

* Fixes for Travis Errors

* Forget to change a variable

* Fast-tracked fix for expired mons not disappearing.

* Travis fixes

* Support for Castform variants (#85)

I'm not saying "form" twice in a commit message

* Fix merge conflict when conds was still cond.

* MOTD 404 fix (#87)

* Fix MOTD 404

* Fixed wrong var name

* Add Deoxys forms (#90)

* Clean up encId code

* Revert stop weather_data calls when weather overlay is disabled

* Workaround for google maps api update (#92)

* workaround for google maps api update

* Small change to use &

* possible fix for mass issue with miniv rewrite. (#93)

* possible fix for mass issue with miniv rewrite.

* Query fixes

* Fixed bug fetch all pokemon when add to exclude min IV/lvl

* Ex eligible gym filter (#86)

* Ex Eligible Gym Filter

* Travis CI fixes

* Travis CI Style

* Adds Sponsor support for EX Raids

* Move EX Eligible outside the gym filter to be seen by both Gym and Raids.
Added default value.

* Fixed defaults for ex-raid filter

* StyleCI Fixes

* fixed non-ex gyms coming back up after toggling ex gyms on and off.

* Changed conditional to check for fork rather than map

* Fixed Castform missing weather sprite forms

* Fixed mobile notifications for all platforms

* Added in apache rewrite rule
removed min from service worker.

* minified Service Worker

* Added into grunt task to minify file.
Updated appropriate links to unminified version

* Added nginx config into example file
  • Loading branch information
hammydown4325 authored and Glennmen committed Feb 22, 2018
1 parent c26c553 commit 059410f
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ RewriteEngine on
RewriteRule ^raw_data$ raw_data.php?$1 [QSA,L]
RewriteRule ^gym_data$ gym_data.php?$1 [QSA,L]
RewriteRule ^motd_data$ motd_data.php?$1 [QSA,L]
RewriteRule ^weather_data$ weather_data.php?$1 [QSA,L]
RewriteRule ^weather_data$ weather_data.php?$1 [QSA,L]
RewriteRule ^serviceWorker.min.js$ static/dist/js/serviceWorker.min.js?$1 [QSA,L]
6 changes: 4 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module.exports = function (grunt) {
'static/dist/js/mobile.built.js': 'static/js/mobile.js',
'static/dist/js/stats.built.js': 'static/js/stats.js',
'static/dist/js/statistics.built.js': 'static/js/statistics.js',
'static/dist/js/status.built.js': 'static/js/status.js'
'static/dist/js/status.built.js': 'static/js/status.js',
'static/dist/js/serviceWorker.built.js': 'static/js/serviceWorker.js'
}
}
},
Expand All @@ -53,7 +54,8 @@ module.exports = function (grunt) {
'static/dist/js/mobile.min.js': 'static/dist/js/mobile.built.js',
'static/dist/js/stats.min.js': 'static/dist/js/stats.built.js',
'static/dist/js/statistics.min.js': 'static/dist/js/statistics.built.js',
'static/dist/js/status.min.js': 'static/dist/js/status.built.js'
'static/dist/js/status.min.js': 'static/dist/js/status.built.js',
'static/dist/js/serviceWorker.min.js': 'static/dist/js/serviceWorker.built.js'
}
}
},
Expand Down
1 change: 1 addition & 0 deletions nginx.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ server {
rewrite ^/gym_data$ /gym_data.php?$1 last;
rewrite ^/motd_data$ /motd_data.php?$1 last;
rewrite ^/weather_data$ /weather_data.php?$1 last;
rewrite ^/serviceWorker.min.js$ /static/dist/js/serviceWorker.min.js last;

#charset koi8-r;

Expand Down
97 changes: 84 additions & 13 deletions static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ function removePokemonMarker(encounterId) { // eslint-disable-line no-unused-var
mapData.pokemons[encounterId].hidden = true
}

function createServiceWorkerReceiver() {
navigator.serviceWorker.addEventListener('message', function (event) {
const data = JSON.parse(event.data)
if (data.action === 'centerMap' && data.lat && data.lon) {
centerMap(data.lat, data.lon, 20)
}
})
}


function initMap() { // eslint-disable-line no-unused-vars
map = new google.maps.Map(document.getElementById('map'), {
center: {
Expand Down Expand Up @@ -305,6 +315,10 @@ function initMap() { // eslint-disable-line no-unused-vars
languageSite = language
}

if (Push._agents.chrome.isSupported()) {
createServiceWorkerReceiver()
}

updateWeatherOverlay()
}

Expand Down Expand Up @@ -360,7 +374,6 @@ function initSidebar() {
$('#ex-eligible-switch').prop('checked', Store.get('exEligible'))
$('#gym-sidebar-wrapper').toggle(Store.get('showGyms') || Store.get('showRaids'))
$('#gyms-filter-wrapper').toggle(Store.get('showGyms'))

$('#team-gyms-only-switch').val(Store.get('showTeamGymsOnly'))
$('#open-gyms-only-switch').prop('checked', Store.get('showOpenGymsOnly'))
$('#raids-switch').prop('checked', Store.get('showRaids'))
Expand Down Expand Up @@ -2098,25 +2111,83 @@ function getPointDistance(pointA, pointB) {
return google.maps.geometry.spherical.computeDistanceBetween(pointA, pointB)
}

function sendNotification(title, text, icon, lat, lng) {
if (!('Notification' in window)) {
return false // Notifications are not present in browser
function sendNotification(title, text, icon, lat, lon) {
var notificationDetails = {
icon: icon,
body: text,
data: {
lat: lat,
lon: lon
}
}

if (Push.Permission.has()) {
Push.create(title, {
icon: icon,
body: text,
vibrate: 1000,
onClick: function () {
if (Push._agents.desktop.isSupported()) {
/* This will only run in browsers which support the old
* Notifications API. Browsers supporting the newer Push API
* are handled by serviceWorker.js. */
notificationDetails.onClick = function (event) {
if (Push._agents.desktop.isSupported()) {
window.focus()
this.close()
centerMap(lat, lng, 20)
event.currentTarget.close()
centerMap(lat, lon, 20)
}
})
}
}

/* Push.js requests the Notification permission automatically if
* necessary. */
Push.create(title, notificationDetails).catch(function () {
sendToastrPokemonNotification(title, text, icon, lat, lon)
})
}

function sendToastrPokemonNotification(title, text, icon, lat, lon) {
var notification = toastr.info(text, title, {
closeButton: true,
positionClass: 'toast-top-right',
preventDuplicates: true,
onclick: function () {
centerMap(lat, lon, 20)
},
showDuration: '300',
hideDuration: '500',
timeOut: '6000',
extendedTimeOut: '1500',
showEasing: 'swing',
hideEasing: 'linear',
showMethod: 'fadeIn',
hideMethod: 'fadeOut'
})
notification.removeClass('toast-info')
notification.css({
'padding-left': '74px',
'background-image': `url('./${icon}')`,
'background-size': '48px',
'background-color': '#0c5952'
})
}

//
// Page Ready Execution
//

$(function () {
/* If push.js is unsupported or disabled, fall back to toastr
* notifications. */
Push.config({
serviceWorker: 'serviceWorker.min.js',
fallback: function (notification) {
sendToastrPokemonNotification(
notification.title,
notification.body,
notification.icon,
notification.data.lat,
notification.data.lon
)
}
})
})

function createMyLocationButton() {
var locationContainer = document.createElement('div')

Expand Down
105 changes: 105 additions & 0 deletions static/js/serviceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Push v1.0-beta
* ==============
* A compact, cross-browser solution for the JavaScript Notifications API
*
* Credits
* -------
* Tsvetan Tsvetkov (ttsvetko)
* Alex Gibson (alexgibson)
*
* License
* -------
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2017 Tyler Nickerson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* global clients */
'use strict'

function isFunction(obj) {
return obj && {}.toString.call(obj) === '[object Function]'
}

function runFunctionString(funcStr) {
if (funcStr.trim().length > 0) {
// eslint-disable-next-line no-new-func
var func = new Function(funcStr)
if (isFunction(func)) {
func()
}
}
}

function findValidClient(clients, origin) {
var validClient = null
for (var i = 0; i < clients.length; i++) {
var client = clients[i]
if (client.url === origin) {
validClient = client
if ('focused' in client && client.focused) {
return client
}
}
}
return validClient
}

function sendCenterMapMessage(client, lat, lon) {
client.postMessage(JSON.stringify({
action: 'centerMap',
lat: lat,
lon: lon
}))
}

self.addEventListener('message', function (event) {
self.client = event.source
})

self.onnotificationclick = function (event) {
event.notification.close()

event.waitUntil(clients.matchAll({includeUncontrolled: true, type: 'window'}).then(function (clientList) {
var client = findValidClient(clientList, event.notification.data.origin)

if (client && 'focus' in client) {
client.focus().then(function (client) {
sendCenterMapMessage(client, event.notification.data.lat, event.notification.data.lon)
})
} else if ('openWindow' in clients) {
clients.openWindow('/').then(function (client) {
sendCenterMapMessage(client, event.notification.data.lat, event.notification.data.lon)
})
}
}))
}

self.onnotificationclose = function (event) {
runFunctionString(event.notification.data.onClose)

/* Tell Push to execute close callback */
self.client.postMessage(JSON.stringify({
id: event.notification.data.id,
action: 'close'
}))
}

0 comments on commit 059410f

Please sign in to comment.