2022-02-05 15:54:14 +00:00
|
|
|
// GridTracker Copyright © 2022 GridTracker.org
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE for more information.
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
var g_pota = {
|
|
|
|
places: {},
|
|
|
|
placesTimeout: null,
|
|
|
|
schedule: {},
|
|
|
|
scheduleTimeout: null,
|
|
|
|
spots: {},
|
|
|
|
spotsTimeout: null
|
|
|
|
};
|
2022-02-05 15:54:14 +00:00
|
|
|
|
2022-09-14 01:13:16 +00:00
|
|
|
var g_parks = {};
|
|
|
|
|
|
|
|
var g_defaultPark = {
|
|
|
|
scheduled: false,
|
|
|
|
spotted: false,
|
|
|
|
feature: false
|
|
|
|
}
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
function initPota()
|
|
|
|
{
|
|
|
|
potaImg.style.filter = g_potaEnabled == 1 ? "" : "grayscale(1)";
|
|
|
|
|
|
|
|
getPotaPlaces();
|
|
|
|
getPotaSchedule();
|
|
|
|
getPotaSpots();
|
|
|
|
}
|
|
|
|
|
|
|
|
function togglePota()
|
|
|
|
{
|
|
|
|
g_potaEnabled ^= 1;
|
|
|
|
g_appSettings.potaEnabled = g_potaEnabled;
|
|
|
|
potaImg.style.filter = g_potaEnabled == 1 ? "" : "grayscale(1)";
|
|
|
|
|
|
|
|
saveAppSettings();
|
|
|
|
|
|
|
|
if (g_potaEnabled == 1)
|
|
|
|
{
|
|
|
|
// Only get if empty, let the timer do its job
|
|
|
|
if (Object.keys(g_pota.places).length == 0)
|
|
|
|
{
|
|
|
|
getPotaPlaces();
|
|
|
|
}
|
|
|
|
getPotaSchedule();
|
|
|
|
getPotaSpots();
|
|
|
|
}
|
2022-09-14 01:13:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_layerSources.pota.clear();
|
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function processPotaPlaces(buffer)
|
2022-02-05 21:55:25 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-09-11 01:05:25 +00:00
|
|
|
g_pota.places = JSON.parse(buffer);
|
2022-02-05 21:55:25 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// can't write, somethings broke
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 15:56:25 +00:00
|
|
|
function getPotaPlaces()
|
2022-02-05 15:54:14 +00:00
|
|
|
{
|
2022-09-11 01:05:25 +00:00
|
|
|
if (g_pota.placesTimeout)
|
|
|
|
{
|
|
|
|
clearTimeout(g_pota.placesTimeout);
|
|
|
|
g_pota.spotsTimeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_mapSettings.offlineMode == false && g_potaEnabled == 1)
|
2022-02-05 21:55:25 +00:00
|
|
|
{
|
|
|
|
getBuffer(
|
2022-05-18 01:38:39 +00:00
|
|
|
"https://storage.googleapis.com/gt_app/pota.json",
|
2022-09-11 01:05:25 +00:00
|
|
|
processPotaPlaces,
|
2022-02-05 21:55:25 +00:00
|
|
|
null,
|
2022-05-18 01:47:35 +00:00
|
|
|
"https",
|
|
|
|
443
|
2022-02-05 21:55:25 +00:00
|
|
|
);
|
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
|
|
|
|
g_pota.placesTimeout = setTimeout(getPotaPlaces, 86400000)
|
2022-02-05 15:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
function processPotaSpots(buffer)
|
2022-02-05 17:36:52 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-09-11 01:05:25 +00:00
|
|
|
let spots = JSON.parse(buffer);
|
|
|
|
g_pota.spots = {};
|
|
|
|
for (let spot in spots)
|
|
|
|
{
|
|
|
|
(g_pota.spots[spots[spot].activator] = g_pota.spots[spots[spot].activator] || []).push(spots[spot].reference);
|
|
|
|
}
|
2022-02-05 17:36:52 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// can't write, somethings broke
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 15:56:25 +00:00
|
|
|
function getPotaSpots()
|
2022-02-05 15:54:14 +00:00
|
|
|
{
|
2022-09-11 01:05:25 +00:00
|
|
|
if (g_pota.spotsTimeout)
|
|
|
|
{
|
|
|
|
clearTimeout(g_pota.spotsTimeout);
|
|
|
|
g_pota.spotsTimeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_mapSettings.offlineMode == false && g_potaEnabled == 1)
|
2022-02-05 17:36:52 +00:00
|
|
|
{
|
|
|
|
getBuffer(
|
|
|
|
"https://api.pota.app/spot/activator",
|
2022-09-11 01:05:25 +00:00
|
|
|
processPotaSpots,
|
2022-02-05 17:36:52 +00:00
|
|
|
null,
|
2022-02-05 18:08:25 +00:00
|
|
|
"https",
|
|
|
|
443
|
2022-02-05 17:36:52 +00:00
|
|
|
);
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_pota.spotsTimeout = setTimeout(getPotaSpots, 300000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function processPotaSchedule(buffer)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
let schedules = JSON.parse(buffer);
|
|
|
|
g_pota.schedule = {};
|
|
|
|
for (let i in schedules)
|
|
|
|
{
|
|
|
|
let newObj = {};
|
|
|
|
newObj.id = schedules[i].reference;
|
|
|
|
newObj.start = Date.parse(schedules[i].startDate + "T" + schedules[i].startTime);
|
|
|
|
newObj.end = Date.parse(schedules[i].endDate + "T" + schedules[i].endTime);
|
|
|
|
|
|
|
|
if (Date.now() < newObj.end)
|
|
|
|
{
|
|
|
|
(g_pota.schedule[schedules[i].activator] = g_pota.schedule[schedules[i].activator] || []).push(newObj);
|
|
|
|
}
|
|
|
|
// else it is expired and no longer relevant
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// can't write, somethings broke
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPotaSchedule()
|
|
|
|
{
|
2022-09-11 20:18:00 +00:00
|
|
|
if (g_pota.scheduleTimeout)
|
2022-09-11 01:05:25 +00:00
|
|
|
{
|
|
|
|
clearTimeout(g_pota.scheduleTimeout);
|
|
|
|
g_pota.scheduleTimeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_mapSettings.offlineMode == false && g_potaEnabled == 1)
|
|
|
|
{
|
|
|
|
getBuffer(
|
|
|
|
"https://api.pota.app/activation",
|
|
|
|
processPotaSchedule,
|
|
|
|
null,
|
|
|
|
"https",
|
|
|
|
443
|
|
|
|
);
|
2022-02-05 17:36:52 +00:00
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
g_pota.scheduleTimeout = setTimeout(getPotaSchedule, 900000);
|
2022-02-05 15:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
function sendPotaSpot()
|
2022-02-05 15:54:14 +00:00
|
|
|
{
|
|
|
|
// if Pota spotting enabled, and we have enough info, send a spot to Pota
|
|
|
|
}
|