bunch of misc changes

This commit is contained in:
Sriram Hariharan
2023-11-17 11:11:01 -06:00
parent 52431747ee
commit 56643f9753
11 changed files with 51 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ const HOT_RELOADING_WHITELIST = [
'reddit.com',
'gmail.com',
'photopea.com',
'chat.openai.com',
];
/**
@@ -39,3 +40,5 @@ export async function hotReloadTab(): Promise<void> {
}
});
}

View File

@@ -1,5 +1,5 @@
import io from 'socket.io-client';
import { bMessenger } from 'src/shared/messages';
import { background } from 'src/shared/messages';
const socket = io('http://localhost:9090');
let reBuilding = false;
@@ -27,7 +27,7 @@ socket.on('reload', async () => {
console.log('%c[hot-reloading] reloading...', 'color:white; background-color: orange;');
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
if (tabs?.[0]?.id) {
bMessenger.reloadExtension();
background.reloadExtension();
}
});
});

View File

@@ -16,9 +16,9 @@ export type BACKGROUND_MESSAGES = BrowserActionMessages &
/**
* A utility object that can be used to send type-safe messages to the background script
*/
export const bMessenger = createMessenger<BACKGROUND_MESSAGES>('background');
export const background = createMessenger<BACKGROUND_MESSAGES>('background');
/**
* A utility object that can be used to send type-safe messages to specific tabs
*/
export const tabMessenger = createMessenger<TAB_MESSAGES>('tab');
export const tabs = createMessenger<TAB_MESSAGES>('tab');

View File

@@ -24,4 +24,10 @@ export const DevStore = createLocalStore<IDevStore>({
reloadTabId: undefined,
});
debugStore({ devStore: DevStore });

View File

@@ -15,4 +15,6 @@ export const ExtensionStore = createLocalStore<IExtensionStore>({
lastUpdate: Date.now(),
});
debugStore({ ExtensionStore });

View File

@@ -8,6 +8,8 @@ interface IOptionsStore {
shouldHighlightConflicts: boolean;
/** whether we should automatically scroll to load more courses on the course schedule page (without having to click next) */
shouldScrollToLoad: boolean;
url: URL;
}
export const OptionsStore = createSyncStore<IOptionsStore>({
@@ -15,4 +17,6 @@ export const OptionsStore = createSyncStore<IOptionsStore>({
shouldScrollToLoad: true,
});
// Clothing retailer right
debugStore({ OptionsStore });

View File

@@ -1,10 +1,9 @@
import React from 'react';
import { bMessenger } from 'src/shared/messages';
import { background } from 'src/shared/messages';
import useSchedules from '../hooks/useSchedules';
import { Button } from './common/Button/Button';
import ExtensionRoot from './common/ExtensionRoot/ExtensionRoot';
const { clearCourses } = bMessenger;
export default function PopupMain() {
const [activeSchedule, schedules] = useSchedules();
@@ -15,7 +14,7 @@ export default function PopupMain() {
<Button
onClick={() => {
if (!activeSchedule) return;
clearCourses({ scheduleName: activeSchedule?.name });
background.clearCourses({ scheduleName: activeSchedule?.name });
}}
>
Clear Courses

View File

@@ -1,6 +1,6 @@
import classNames from 'classnames';
import React, { PropsWithChildren } from 'react';
import { bMessenger } from 'src/shared/messages';
import { background } from 'src/shared/messages';
import Text, { TextProps } from '../Text/Text';
import styles from './Link.module.scss';
@@ -20,7 +20,7 @@ export default function Link(props: PropsWithChildren<Props>) {
const { url } = props;
if (url && !props.onClick) {
passedProps.onClick = () => bMessenger.openNewTab({ url });
passedProps.onClick = () => background.openNewTab({ url });
}
const isDisabled = props.disabled || (!url && !props.onClick);

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { bMessenger } from 'src/shared/messages';
import { background } from 'src/shared/messages';
import { Course } from 'src/shared/types/Course';
import { UserSchedule } from 'src/shared/types/UserSchedule';
import { Button } from 'src/views/components/common/Button/Button';
@@ -13,7 +13,7 @@ type Props = {
course: Course;
};
const { openNewTab, addCourse, removeCourse } = bMessenger;
const { openNewTab, addCourse, removeCourse } = background;
/**
* This component displays the buttons for the course info popup, that allow the user to either

View File

@@ -0,0 +1,20 @@
import { Serialized } from 'chrome-extension-toolkit';
import { useEffect, useState } from 'react';
import { ExtensionStore } from 'src/shared/storage/ExtensionStore';
export default function useVersion(): string {
const [version, setVersion] = useState<string>('');
useEffect(() => {
const listener = ExtensionStore.listen('version', ({ newValue }) => {
setVersion(newValue);
});
return () => {
ExtensionStore.removeListener(listener);
};
}, []);
return version;
}

View File

@@ -1,4 +1,5 @@
import React from 'react';
import { background } from 'src/shared/messages';
import render from './lib/react';
import { ContextInvalidated, createShadowDOM, isExtensionPopup, onContextInvalidated } from 'chrome-extension-toolkit';
@@ -14,6 +15,11 @@ if (!support) {
throw new Error('UT Registration Plus does not support this page, even though it should...');
}
// if we are in an iframe, throw an error
if (window.self !== window.top) {
throw new Error('inside an iframe');
}
if (support === SiteSupport.EXTENSION_POPUP) {
render(<PopupMain />, document.getElementById('root'));
}