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(); diff --git a/components/parental_control/extension/service_worker/background.js b/components/parental_control/extension/service_worker/background.js index 4596f4c09682..3dc47edb5082 100644 --- a/components/parental_control/extension/service_worker/background.js +++ b/components/parental_control/extension/service_worker/background.js @@ -3,13 +3,28 @@ 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 +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 +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: '../content/ui/sessionTimeout.html' }); + chrome.tabs.update(tab.id, { url: sessionTimeoutUrl }); } else if (data.loggedIn && !data.sessionTimeout) { startTimer(); @@ -35,20 +50,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'; - await handleBrowserWindows(url); + await handleBrowserWindows(true); } // Function to block Google search URLs @@ -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 (isSessionTimeout) => { + let newWindow; + if(isSessionTimeout) + newWindow = await chrome.windows.create({ url: sessionTimeoutUrl, 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 {