Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show calendar in active window #312

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/pages/background/handler/calendarBackgroundHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Awaited<ReturnType<typeof tabs.getTabInfo>>>;
Expand All @@ -28,10 +30,14 @@ const calendarBackgroundHandler: MessageHandler<CalendarBackgroundMessages> = {
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 {
Expand Down
Loading