feat: inline chrome-extension-toolkit (#744)

* feat(build): inline chrome-extension-toolkit

fix: tsconfig

docs: add chrome-extension-toolkit README.md

chore: update imports

fix: stores

fix: chrome-extension-toolkit ForegroundMessenger

fix: calendarBackgroundHandler

fix: format and lint

fix: path alias

fix: add jsdom env and fix imports

Co-authored-by: Sriram Hariharan <sghsri@gmail.com>

* build: vite storybook config crx toolkit line

---------

Co-authored-by: Sriram Hariharan <sghsri@gmail.com>
Co-authored-by: Derek <derex1987@gmail.com>
This commit is contained in:
Diego Perez
2026-02-11 00:50:27 -06:00
committed by GitHub
parent d5954410a7
commit a537d17a2f
67 changed files with 1833 additions and 92 deletions

View File

@@ -37,7 +37,7 @@ export default function PopupMain(): JSX.Element {
initAllSettings();
const l1 = OptionsStore.listen('enableCourseStatusChips', async ({ newValue }) => {
const l1 = OptionsStore.subscribe('enableCourseStatusChips', async ({ newValue }) => {
setEnableCourseStatusChips(newValue);
// console.log('enableCourseStatusChips', newValue);
});
@@ -48,7 +48,7 @@ export default function PopupMain(): JSX.Element {
// });
return () => {
OptionsStore.removeListener(l1);
OptionsStore.unsubscribe(l1);
// OptionsStore.removeListener(l2);
};
}, []);

View File

@@ -1,3 +1,4 @@
import { MessageListener } from '@chrome-extension-toolkit';
import { Sidebar } from '@phosphor-icons/react';
import type { CalendarTabMessages } from '@shared/messages/CalendarMessages';
import { OptionsStore } from '@shared/storage/OptionsStore';
@@ -16,7 +17,6 @@ import { CalendarContext } from '@views/contexts/CalendarContext';
import useCourseFromUrl from '@views/hooks/useCourseFromUrl';
import { useFlattenedCourseSchedule } from '@views/hooks/useFlattenedCourseSchedule';
import useWhatsNewPopUp from '@views/hooks/useWhatsNew';
import { MessageListener } from 'chrome-extension-toolkit';
import clsx from 'clsx';
import type { ReactNode } from 'react';
import React, { useEffect, useState } from 'react';

View File

@@ -61,13 +61,13 @@ export default function CalendarCourseCell({
useEffect(() => {
initSettings().then(({ enableCourseStatusChips }) => setEnableCourseStatusChips(enableCourseStatusChips));
const l1 = OptionsStore.listen('enableCourseStatusChips', async ({ newValue }) => {
const l1 = OptionsStore.subscribe('enableCourseStatusChips', async ({ newValue }) => {
setEnableCourseStatusChips(newValue);
// console.log('enableCourseStatusChips', newValue);
});
return () => {
OptionsStore.removeListener(l1);
OptionsStore.unsubscribe(l1);
};
}, []);

View File

@@ -1,8 +1,8 @@
import type { Serialized } from '@chrome-extension-toolkit';
import { tz } from '@date-fns/tz';
import { Course } from '@shared/types/Course';
import { UserSchedule } from '@shared/types/UserSchedule';
import type { CalendarGridCourse } from '@views/hooks/useFlattenedCourseSchedule';
import type { Serialized } from 'chrome-extension-toolkit';
import { format as formatDate, parseISO } from 'date-fns';
import {
chatterjeeCS429Course,

View File

@@ -1,3 +1,4 @@
import type { Serialized } from '@chrome-extension-toolkit';
import { tz, TZDate } from '@date-fns/tz';
import exportSchedule from '@pages/background/lib/exportSchedule';
import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
@@ -8,7 +9,6 @@ import type { UserSchedule } from '@shared/types/UserSchedule';
import { downloadBlob } from '@shared/util/downloadBlob';
import { englishStringifyList } from '@shared/util/string';
import type { CalendarGridCourse } from '@views/hooks/useFlattenedCourseSchedule';
import type { Serialized } from 'chrome-extension-toolkit';
import type { DateArg, Day } from 'date-fns';
import {
addDays,

View File

@@ -61,7 +61,7 @@ export default function PopupCourseBlock({ className, course, colors }: PopupCou
initAllSettings();
const l1 = OptionsStore.listen('enableCourseStatusChips', async ({ newValue }) => {
const l1 = OptionsStore.subscribe('enableCourseStatusChips', async ({ newValue }) => {
setEnableCourseStatusChips(newValue);
});
@@ -77,7 +77,7 @@ export default function PopupCourseBlock({ className, course, colors }: PopupCou
});
return () => {
OptionsStore.removeListener(l1);
OptionsStore.unsubscribe(l1);
};
}, []);

View File

@@ -34,14 +34,14 @@ export default function TableRow({ row, isSelected, activeSchedule, onClick }: P
setHighlightConflicts(enableHighlightConflicts);
});
const l1 = OptionsStore.listen('enableHighlightConflicts', async ({ newValue }) => {
const l1 = OptionsStore.subscribe('enableHighlightConflicts', async ({ newValue }) => {
setHighlightConflicts(newValue);
// console.log('enableHighlightConflicts', newValue);
});
// Remove listeners when the component is unmounted
return () => {
OptionsStore.removeListener(l1);
OptionsStore.unsubscribe(l1);
};
}, []);

View File

@@ -98,23 +98,23 @@ export default function Settings(): JSX.Element {
};
// Listeners
const ds_l1 = DevStore.listen('isDeveloper', async ({ newValue }) => {
const ds_l1 = DevStore.subscribe('isDeveloper', async ({ newValue }) => {
setIsDeveloper(newValue);
});
const l1 = OptionsStore.listen('enableHighlightConflicts', async ({ newValue }) => {
const l1 = OptionsStore.subscribe('enableHighlightConflicts', async ({ newValue }) => {
setHighlightConflicts(newValue);
});
const l2 = OptionsStore.listen('enableScrollToLoad', async ({ newValue }) => {
const l2 = OptionsStore.subscribe('enableScrollToLoad', async ({ newValue }) => {
setLoadAllCourses(newValue);
});
const l3 = OptionsStore.listen('alwaysOpenCalendarInNewTab', async ({ newValue }) => {
const l3 = OptionsStore.subscribe('alwaysOpenCalendarInNewTab', async ({ newValue }) => {
setCalendarNewTab(newValue);
});
const l4 = OptionsStore.listen('allowMoreSchedules', async ({ newValue }) => {
const l4 = OptionsStore.subscribe('allowMoreSchedules', async ({ newValue }) => {
setIncreaseScheduleLimit(newValue);
});
@@ -125,11 +125,11 @@ export default function Settings(): JSX.Element {
initAndSetSettings();
return () => {
OptionsStore.removeListener(l1);
OptionsStore.removeListener(l2);
OptionsStore.removeListener(l3);
OptionsStore.removeListener(l4);
DevStore.removeListener(ds_l1);
OptionsStore.unsubscribe(l1);
OptionsStore.unsubscribe(l2);
OptionsStore.unsubscribe(l3);
OptionsStore.unsubscribe(l4);
DevStore.unsubscribe(ds_l1);
window.removeEventListener('keydown', handleKeyPress);
};
}, [gitHubStatsService]);

View File

@@ -33,13 +33,13 @@ export function useEnforceScheduleLimit(): () => boolean {
}
})();
const listener = OptionsStore.listen('allowMoreSchedules', async ({ newValue }) => {
const listener = OptionsStore.subscribe('allowMoreSchedules', async ({ newValue }) => {
setAllowMoreSchedules(newValue);
});
return () => {
mounted = false;
OptionsStore.removeListener(listener);
OptionsStore.unsubscribe(listener);
};
}, []);

View File

@@ -48,19 +48,19 @@ export default function useSchedules(): [active: UserSchedule, schedules: UserSc
}
useEffect(() => {
const l1 = UserScheduleStore.listen('schedules', ({ newValue }) => {
const l1 = UserScheduleStore.subscribe('schedules', ({ newValue }) => {
schedulesCache = newValue.map(s => new UserSchedule(s));
setSchedules(schedulesCache);
});
const l2 = UserScheduleStore.listen('activeIndex', ({ newValue }) => {
const l2 = UserScheduleStore.subscribe('activeIndex', ({ newValue }) => {
activeIndexCache = newValue;
setActiveIndex(newValue);
});
return () => {
UserScheduleStore.removeListener(l1);
UserScheduleStore.removeListener(l2);
UserScheduleStore.unsubscribe(l1);
UserScheduleStore.unsubscribe(l2);
};
}, []);

View File

@@ -1,4 +1,4 @@
import { createUseMessage } from '@chrome-extension-toolkit';
import type { TAB_MESSAGES } from '@shared/messages';
import { createUseMessage } from 'chrome-extension-toolkit';
export const useTabMessage = createUseMessage<TAB_MESSAGES>();

View File

@@ -9,12 +9,12 @@ export default function useVersion(): string {
const [version, setVersion] = useState<string>('');
useEffect(() => {
const listener = ExtensionStore.listen('version', ({ newValue }) => {
const listener = ExtensionStore.subscribe('version', ({ newValue }) => {
setVersion(newValue);
});
return () => {
ExtensionStore.removeListener(listener);
ExtensionStore.unsubscribe(listener);
};
}, []);

View File

@@ -1,4 +1,4 @@
import { ContextInvalidated, createShadowDOM, onContextInvalidated } from 'chrome-extension-toolkit';
import { ContextInvalidated, createShadowDOM, onContextInvalidated } from '@chrome-extension-toolkit';
import React from 'react';
import CourseCatalogMain from './components/CourseCatalogMain';

View File

@@ -1,4 +1,4 @@
import { isExtensionPage, isExtensionPopup } from 'chrome-extension-toolkit';
import { isExtensionPage, isExtensionPopup } from '@chrome-extension-toolkit';
/**
* An enum that represents the different types of pages that we support

View File

@@ -1,4 +1,4 @@
import { createMessenger } from 'chrome-extension-toolkit';
import { createMessenger } from '@chrome-extension-toolkit';
type MyMessages = {
openNewTab: (data: { url: string }) => void;