|
|
@ -2,6 +2,8 @@
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var shown_notifications = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Switches the app to the given screen.
|
|
|
|
* Switches the app to the given screen.
|
|
|
|
* @param {String} screenname The name of the screen to show.
|
|
|
|
* @param {String} screenname The name of the screen to show.
|
|
|
@ -198,6 +200,42 @@ function restartApplication() {
|
|
|
|
}, 3000);
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function displayNotifications(callback) {
|
|
|
|
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
|
|
|
|
|
password: localStorage.getItem("password"),
|
|
|
|
|
|
|
|
action: "checknotifications"
|
|
|
|
|
|
|
|
}, function (data) {
|
|
|
|
|
|
|
|
if (data.status === 'OK') {
|
|
|
|
|
|
|
|
for (var i = 0; i < data.notifications.length; i++) {
|
|
|
|
|
|
|
|
var n = data.notifications[i];
|
|
|
|
|
|
|
|
if (n.seen || shown_notifications.includes(n.id)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cordova.plugins.notification.local.schedule([{
|
|
|
|
|
|
|
|
title: n.title,
|
|
|
|
|
|
|
|
text: n.content,
|
|
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
|
|
{id: 'mark_read', title: "Mark Read"}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
id: n.id
|
|
|
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shown_notifications.push(n.id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, "json").fail(function () {
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Handle back button to close things
|
|
|
|
// Handle back button to close things
|
|
|
|
document.addEventListener("backbutton", function (event) {
|
|
|
|
document.addEventListener("backbutton", function (event) {
|
|
|
|
if (isconfigvalid()) {
|
|
|
|
if (isconfigvalid()) {
|
|
|
@ -225,6 +263,20 @@ document.addEventListener("deviceready", function () {
|
|
|
|
StatusBar.backgroundColorByHexString("#1976d2");
|
|
|
|
StatusBar.backgroundColorByHexString("#1976d2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cordova.plugins.notification.local.setDefaults({
|
|
|
|
|
|
|
|
led: {color: '#2196F3'},
|
|
|
|
|
|
|
|
smallIcon: "res://ic_notification"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
cordova.plugins.notification.local.on("mark_read", function (notification) {
|
|
|
|
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
|
|
|
|
|
password: localStorage.getItem("password"),
|
|
|
|
|
|
|
|
action: "readnotification",
|
|
|
|
|
|
|
|
id: notification.id
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Enable/disable jQuery animations depending on user preference
|
|
|
|
// Enable/disable jQuery animations depending on user preference
|
|
|
|
$.fx.off = !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true");
|
|
|
|
$.fx.off = !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true");
|
|
|
|
|
|
|
|
|
|
|
@ -236,6 +288,32 @@ document.addEventListener("deviceready", function () {
|
|
|
|
if (isconfigvalid()) {
|
|
|
|
if (isconfigvalid()) {
|
|
|
|
getuserinfo(function () {
|
|
|
|
getuserinfo(function () {
|
|
|
|
openscreen("home");
|
|
|
|
openscreen("home");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(displayNotifications, 30 * 1000);
|
|
|
|
|
|
|
|
if (typeof cordova.plugins.notification.local.launchDetails === 'undefined') {
|
|
|
|
|
|
|
|
displayNotifications();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var BackgroundFetch = window.BackgroundFetch;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Your background-fetch handler.
|
|
|
|
|
|
|
|
var fetchCallback = function () {
|
|
|
|
|
|
|
|
console.log('[js] BackgroundFetch event received');
|
|
|
|
|
|
|
|
displayNotifications(function () {
|
|
|
|
|
|
|
|
BackgroundFetch.finish();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var failureCallback = function (error) {
|
|
|
|
|
|
|
|
console.log('- BackgroundFetch failed', error);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BackgroundFetch.configure(fetchCallback, failureCallback, {
|
|
|
|
|
|
|
|
minimumFetchInterval: 1,
|
|
|
|
|
|
|
|
stopOnTerminate: false,
|
|
|
|
|
|
|
|
startOnBoot: true,
|
|
|
|
|
|
|
|
forceReload: true
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
openscreen("setup1");
|
|
|
|
openscreen("setup1");
|
|
|
|