implemented page visibility api for cashier status

This commit is contained in:
sairaj mote 2022-06-04 16:58:13 +05:30
parent 42c8670d3f
commit 11f17b919a
3 changed files with 10 additions and 1 deletions

View File

@ -184,7 +184,6 @@ function statusReconnect() {
}
var status_interval_instance = null;
// add page visibility API to startStatusInterval()
function startStatusInterval() {
if (status_interval_instance) {
clearInterval(status_interval_instance);

View File

@ -15,6 +15,7 @@ function syncUserData(obsName, data) {
const dataToSend = Crypto.AES.encrypt(JSON.stringify(data), myPrivKey);
return floCloudAPI.sendApplicationData(dataToSend, obsName, { receiverID: myFloID });
}
// store user data in separate IDB
async function organizeSyncedData(obsName) {
const fetchedData = await floCloudAPI.requestApplicationData(obsName, { mostRecent: true, senderIDs: [myFloID], receiverID: myFloID });
if (fetchedData.length && await compactIDB.readData(obsName, 'lastSyncTime') !== fetchedData[0].time) {

View File

@ -864,4 +864,13 @@ function randomString(length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
document.addEventListener("visibilitychange", handleVisibilityChange, false);
function handleVisibilityChange() {
if (document.visibilityState === "hidden") {
// code if page is hidden
} else {
startStatusInterval()
}
}