feat(settings): add option to always open calendar in new tab (#488)

* feat(settings): add option to always open calendar in new tab

* fix: await setting

---------

Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
This commit is contained in:
Samuel Gunter
2025-01-20 23:18:00 -06:00
committed by GitHub
parent b74c698866
commit 009de62828
3 changed files with 39 additions and 2 deletions

View File

@@ -2,6 +2,8 @@ import type { TabWithId } from '@background/util/openNewTab';
import openNewTab from '@background/util/openNewTab';
import { tabs } from '@shared/messages';
import type { CalendarBackgroundMessages } from '@shared/messages/CalendarMessages';
import { OptionsStore } from '@shared/storage/OptionsStore';
import { CRX_PAGES } from '@shared/types/CRXPages';
import type { MessageHandler } from 'chrome-extension-toolkit';
const getAllTabInfos = async () => {
@@ -21,13 +23,13 @@ const getAllTabInfos = async () => {
const calendarBackgroundHandler: MessageHandler<CalendarBackgroundMessages> = {
async switchToCalendarTab({ data, sendResponse }) {
const { uniqueId } = data;
const calendarUrl = chrome.runtime.getURL(`calendar.html`);
const calendarUrl = chrome.runtime.getURL(CRX_PAGES.CALENDAR);
const allTabs = await getAllTabInfos();
const openCalendarTabInfo = allTabs.find(tab => tab.url?.startsWith(calendarUrl));
if (openCalendarTabInfo !== undefined) {
if (openCalendarTabInfo !== undefined && !(await OptionsStore.get('alwaysOpenCalendarInNewTab'))) {
const tabid = openCalendarTabInfo.tab.id;
await chrome.tabs.update(tabid, { active: true });