From 11f17b919a0afe748f67cd789bee621d17f08c59 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sat, 4 Jun 2022 16:58:13 +0530 Subject: [PATCH] implemented page visibility api for cashier status --- scripts/fn_pay.js | 1 - scripts/fn_ui.js | 1 + scripts/std_ui.js | 9 +++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/fn_pay.js b/scripts/fn_pay.js index 3f8078d..610214f 100644 --- a/scripts/fn_pay.js +++ b/scripts/fn_pay.js @@ -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); diff --git a/scripts/fn_ui.js b/scripts/fn_ui.js index c546955..10fc42b 100644 --- a/scripts/fn_ui.js +++ b/scripts/fn_ui.js @@ -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) { diff --git a/scripts/std_ui.js b/scripts/std_ui.js index 9b83a77..db4c316 100644 --- a/scripts/std_ui.js +++ b/scripts/std_ui.js @@ -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() + } } \ No newline at end of file