From b34a3a6de074c6b8f9d47920dbb3ec6b0728fd47 Mon Sep 17 00:00:00 2001 From: nikhil7174 Date: Fri, 25 Oct 2024 22:46:55 +0530 Subject: [PATCH 1/4] parental control sessionTimeout fixes --- components/parental_control/extension/content/ui/popup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/parental_control/extension/content/ui/popup.js b/components/parental_control/extension/content/ui/popup.js index 6221c866eb78..7794cf769e02 100644 --- a/components/parental_control/extension/content/ui/popup.js +++ b/components/parental_control/extension/content/ui/popup.js @@ -200,10 +200,14 @@ const updateTimeLeftUI = async () => { if (timeLeft <= 0) { clearInterval(intervalId); timeText.textContent = "Time's up"; + timeHours.textContent = "00"; + timeMinutes.textContent = "00"; } } else { clearInterval(intervalId); timeText.textContent = "Time's up"; + timeHours.textContent = "00"; + timeMinutes.textContent = "00"; } }; await updateTimer(); From 50bd2802f0e6bae1b2e12ef8326e398808828893 Mon Sep 17 00:00:00 2001 From: nikhil7174 Date: Fri, 25 Oct 2024 23:56:44 +0530 Subject: [PATCH 2/4] some fixes --- .../extension/service_worker/background.js | 58 ++++++++++++++----- .../extension/content/ui/style.css | 6 +- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/components/parental_control/extension/service_worker/background.js b/components/parental_control/extension/service_worker/background.js index 4596f4c09682..0b8e1ac7cef4 100644 --- a/components/parental_control/extension/service_worker/background.js +++ b/components/parental_control/extension/service_worker/background.js @@ -6,10 +6,24 @@ const LOCAL_STORAGE_UPDATE_INTERVAL = 2e4; let timerId; // Function to restart the timer with the remaining time when the first window is opened again +const clearAllTimers = () => { + if (timerId) { + clearTimeout(timerId); + timerId = null; + } + if (intervalId) { + clearInterval(intervalId); + intervalId = null; + } +} + const startTimer = async () => { try { const data = await chrome.storage.local.get(['timeLeft', 'loggedIn', 'sessionTimeout']) if (!data.loggedIn || data.sessionTimeout) return; + + clearAllTimers(); + if (data.timeLeft) { timerId = setTimeout(sessionTimeout, data.timeLeft); updateTimeInLocalStorage(data.timeLeft); @@ -25,7 +39,7 @@ chrome.tabs.onCreated.addListener(async (tab) => { chrome.action.setIcon({ path: "../assets/Logo_active.png" }); } if (data.loggedIn && data.sessionTimeout) { - chrome.tabs.update(tab.id, { url: '../content/ui/sessionTimeout.html' }); + chrome.tabs.update(tab.id, { url: 'extension/content/ui/sessionTimeout.html' }); } else if (data.loggedIn && !data.sessionTimeout) { startTimer(); @@ -35,19 +49,24 @@ chrome.tabs.onCreated.addListener(async (tab) => { // Function to update time in local storage every minute let intervalId; const updateTimeInLocalStorage = async (timeLeft) => { + if (intervalId) { + clearInterval(intervalId); + } + intervalId = setInterval(async () => { timeLeft -= LOCAL_STORAGE_UPDATE_INTERVAL; await chrome.storage.local.set({ timeLeft: timeLeft }) if (timeLeft < 0) { - clearInterval(intervalId) + clearInterval(intervalId); + intervalId = null; } - }, LOCAL_STORAGE_UPDATE_INTERVAL); // 20000 milliseconds = 20 sec + }, LOCAL_STORAGE_UPDATE_INTERVAL); } const sessionTimeout = async () => { await blockHttpsSearch(); await chrome.storage.local.set({ sessionTimeout: true }); - const url = '../content/ui/sessionTimeout.html'; + const url = 'extension/content/ui/sessionTimeout.html'; await handleBrowserWindows(url); } @@ -146,9 +165,12 @@ const logoutUser = async (password, sendResponse) => { try { chrome.action.setIcon({ path: "../assets/Logo_inactive.png" }); removeServiceWorker(); - clearTimeout(timerId); - clearInterval(intervalId) - await chrome.storage.local.set({ loggedIn: false, sessionTimeout: false }) + clearAllTimers(); + await chrome.storage.local.set({ + loggedIn: false, + sessionTimeout: false, + timeLeft: 0 // Reset timeLeft to prevent any lingering timer state + }) sendResponse({ status: true }); await allowHttpsSearchAsync(); await handleBrowserWindows(); @@ -160,14 +182,20 @@ const logoutUser = async (password, sendResponse) => { } } -const handleBrowserWindows = async (url) => { - const windows = await chrome.windows.getAll({ populate: true }) - windows.forEach((window) => { - chrome.windows.remove(window.id); - }); - if (!url) await chrome.windows.create({ type: 'normal' }); - else chrome.windows.create({ url: url, type: 'normal' }); -} +const handleBrowserWindows = async (url) => { + let newWindow; + if(url === 'extension/content/ui/sessionTimeout.html') + newWindow = await chrome.windows.create({ url: url, type: 'normal' }); + else + newWindow = await chrome.windows.create({ type: 'normal' }); + + const windows = await chrome.windows.getAll({ populate: true }); + for (const window of windows) { + if (window.id !== newWindow.id) { + chrome.windows.remove(window.id); + } + } +}; const updateBlockingRules = async (rulesToInject) => { const oldRules = await chrome.declarativeNetRequest.getDynamicRules(); diff --git a/components/ping_ai_copilot/extension/content/ui/style.css b/components/ping_ai_copilot/extension/content/ui/style.css index 86c4c404adce..581d10153287 100644 --- a/components/ping_ai_copilot/extension/content/ui/style.css +++ b/components/ping_ai_copilot/extension/content/ui/style.css @@ -144,8 +144,8 @@ } #iconImage { - width: 40px; - height: 40px; + width: 27px; + height: 27px; border-radius: 50%; cursor: pointer; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.26); @@ -153,7 +153,7 @@ } #iconImage:hover { - box-shadow: 0 8px 16px rgba(0, 0, 0, 0.32); + box-shadow: 0 6px 12px rgba(0, 0, 0, 0.32); } #summary-box { From b2b670acd8c303049ea7e1f55f5a0ccb1196c8a5 Mon Sep 17 00:00:00 2001 From: nikhil7174 Date: Mon, 28 Oct 2024 00:02:39 +0530 Subject: [PATCH 3/4] minor changes --- .../extension/service_worker/background.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/parental_control/extension/service_worker/background.js b/components/parental_control/extension/service_worker/background.js index 0b8e1ac7cef4..6d2eaa7bbc15 100644 --- a/components/parental_control/extension/service_worker/background.js +++ b/components/parental_control/extension/service_worker/background.js @@ -3,6 +3,7 @@ import { socialMediaBlockRules } from "../assets/rules/socialMediaBlockRules.js" import { gamingSiteRules } from "../assets/rules/gamesBlockRules.js"; const LOCAL_STORAGE_UPDATE_INTERVAL = 2e4; +const sessionTimeoutUrl = 'extension/content/ui/sessionTimeout.html'; let timerId; // Function to restart the timer with the remaining time when the first window is opened again @@ -39,7 +40,7 @@ chrome.tabs.onCreated.addListener(async (tab) => { chrome.action.setIcon({ path: "../assets/Logo_active.png" }); } if (data.loggedIn && data.sessionTimeout) { - chrome.tabs.update(tab.id, { url: 'extension/content/ui/sessionTimeout.html' }); + chrome.tabs.update(tab.id, { url: sessionTimeoutUrl }); } else if (data.loggedIn && !data.sessionTimeout) { startTimer(); @@ -66,8 +67,7 @@ const updateTimeInLocalStorage = async (timeLeft) => { const sessionTimeout = async () => { await blockHttpsSearch(); await chrome.storage.local.set({ sessionTimeout: true }); - const url = 'extension/content/ui/sessionTimeout.html'; - await handleBrowserWindows(url); + await handleBrowserWindows(sessionTimeoutUrl); } // Function to block Google search URLs @@ -182,10 +182,10 @@ const logoutUser = async (password, sendResponse) => { } } -const handleBrowserWindows = async (url) => { +const handleBrowserWindows = async (isSessionTimeout) => { let newWindow; - if(url === 'extension/content/ui/sessionTimeout.html') - newWindow = await chrome.windows.create({ url: url, type: 'normal' }); + if(isSessionTimeout) + newWindow = await chrome.windows.create({ url: sessionTimeoutUrl, type: 'normal' }); else newWindow = await chrome.windows.create({ type: 'normal' }); From 5aafd3a24397772a46340413396a1649a55586ca Mon Sep 17 00:00:00 2001 From: nikhil7174 Date: Mon, 28 Oct 2024 00:21:49 +0530 Subject: [PATCH 4/4] minor changes --- .../parental_control/extension/service_worker/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/parental_control/extension/service_worker/background.js b/components/parental_control/extension/service_worker/background.js index 6d2eaa7bbc15..3dc47edb5082 100644 --- a/components/parental_control/extension/service_worker/background.js +++ b/components/parental_control/extension/service_worker/background.js @@ -67,7 +67,7 @@ const updateTimeInLocalStorage = async (timeLeft) => { const sessionTimeout = async () => { await blockHttpsSearch(); await chrome.storage.local.set({ sessionTimeout: true }); - await handleBrowserWindows(sessionTimeoutUrl); + await handleBrowserWindows(true); } // Function to block Google search URLs