From f3f2e88627130f90b1cd01fbaa3dd4fcd2c6975b Mon Sep 17 00:00:00 2001 From: Samuel Gunter Date: Wed, 16 Oct 2024 13:08:24 -0500 Subject: [PATCH 1/2] fix: show calendar in active window --- .../handler/calendarBackgroundHandler.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/background/handler/calendarBackgroundHandler.ts b/src/pages/background/handler/calendarBackgroundHandler.ts index d9cc56b39..d9ba87793 100644 --- a/src/pages/background/handler/calendarBackgroundHandler.ts +++ b/src/pages/background/handler/calendarBackgroundHandler.ts @@ -5,7 +5,9 @@ import type { CalendarBackgroundMessages } from '@shared/messages/CalendarMessag import type { MessageHandler } from 'chrome-extension-toolkit'; const getAllTabInfos = async () => { - const openTabs = (await chrome.tabs.query({})).filter((tab): tab is TabWithId => tab.id !== undefined); + const openTabs = (await chrome.tabs.query({ currentWindow: true })).filter( + (tab): tab is TabWithId => tab.id !== undefined + ); const results = await Promise.allSettled(openTabs.map(tab => tabs.getTabInfo(undefined, tab.id))); type TabInfo = PromiseFulfilledResult>>; @@ -28,10 +30,14 @@ const calendarBackgroundHandler: MessageHandler = { const openCalendarTabInfo = allTabs.find(tab => tab.url?.startsWith(calendarUrl)); if (openCalendarTabInfo !== undefined) { - const tabid = openCalendarTabInfo.tab.id; - - chrome.tabs.update(tabid, { active: true }); - if (uniqueId !== undefined) await tabs.openCoursePopup({ uniqueId }, tabid); + const tabId = openCalendarTabInfo.tab.id; + + await chrome.tabs.update(tabId, { active: true }); + await chrome.scripting.executeScript({ + target: { tabId }, + func: () => window.focus(), + }); + if (uniqueId !== undefined) await tabs.openCoursePopup({ uniqueId }, tabId); sendResponse(openCalendarTabInfo.tab); } else { From cef0de548b6a4d4ef330b106b2c65fbd3ec73819 Mon Sep 17 00:00:00 2001 From: Razboy20 Date: Wed, 16 Oct 2024 17:07:11 -0500 Subject: [PATCH 2/2] fix: update calendarBackgroundHandler.ts --- .../handler/calendarBackgroundHandler.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pages/background/handler/calendarBackgroundHandler.ts b/src/pages/background/handler/calendarBackgroundHandler.ts index d9ba87793..4181faadc 100644 --- a/src/pages/background/handler/calendarBackgroundHandler.ts +++ b/src/pages/background/handler/calendarBackgroundHandler.ts @@ -5,9 +5,7 @@ import type { CalendarBackgroundMessages } from '@shared/messages/CalendarMessag import type { MessageHandler } from 'chrome-extension-toolkit'; const getAllTabInfos = async () => { - const openTabs = (await chrome.tabs.query({ currentWindow: true })).filter( - (tab): tab is TabWithId => tab.id !== undefined - ); + const openTabs = (await chrome.tabs.query({})).filter((tab): tab is TabWithId => tab.id !== undefined); const results = await Promise.allSettled(openTabs.map(tab => tabs.getTabInfo(undefined, tab.id))); type TabInfo = PromiseFulfilledResult>>; @@ -30,14 +28,11 @@ const calendarBackgroundHandler: MessageHandler = { const openCalendarTabInfo = allTabs.find(tab => tab.url?.startsWith(calendarUrl)); if (openCalendarTabInfo !== undefined) { - const tabId = openCalendarTabInfo.tab.id; - - await chrome.tabs.update(tabId, { active: true }); - await chrome.scripting.executeScript({ - target: { tabId }, - func: () => window.focus(), - }); - if (uniqueId !== undefined) await tabs.openCoursePopup({ uniqueId }, tabId); + const tabid = openCalendarTabInfo.tab.id; + + await chrome.tabs.update(tabid, { active: true }); + await chrome.windows.update(openCalendarTabInfo.tab.windowId, { focused: true, drawAttention: true }); + if (uniqueId !== undefined) await tabs.openCoursePopup({ uniqueId }, tabid); sendResponse(openCalendarTabInfo.tab); } else {