refactor: Replace Webpack with Vite (#53)
This commit is contained in:
20
src/pages/background/handler/browserActionHandler.ts
Normal file
20
src/pages/background/handler/browserActionHandler.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import BrowserActionMessages from '@shared/messages/BrowserActionMessages';
|
||||
import { MessageHandler } from 'chrome-extension-toolkit';
|
||||
|
||||
const browserActionHandler: MessageHandler<BrowserActionMessages> = {
|
||||
disableBrowserAction({ sender, sendResponse }) {
|
||||
// by setting the popup to an empty string, clicking the browser action will not open the popup.html.
|
||||
// we can then add an onClickListener to it from the content script
|
||||
chrome.action.setPopup({ tabId: sender.tab?.id, popup: '' }).then(sendResponse);
|
||||
},
|
||||
enableBrowserAction({ sender, sendResponse }) {
|
||||
chrome.action
|
||||
.setPopup({
|
||||
tabId: sender.tab?.id,
|
||||
popup: 'popup.html',
|
||||
})
|
||||
.then(sendResponse);
|
||||
},
|
||||
};
|
||||
|
||||
export default browserActionHandler;
|
||||
24
src/pages/background/handler/hotReloadingHandler.ts
Normal file
24
src/pages/background/handler/hotReloadingHandler.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import HotReloadingMessages from '@shared/messages/HotReloadingMessages';
|
||||
import { DevStore } from '@shared/storage/DevStore';
|
||||
import { MessageHandler } from 'chrome-extension-toolkit';
|
||||
|
||||
const hotReloadingHandler: MessageHandler<HotReloadingMessages> = {
|
||||
async reloadExtension({ sendResponse }) {
|
||||
const [isExtensionReloading, isTabReloading] = await Promise.all([
|
||||
DevStore.get('isExtensionReloading'),
|
||||
DevStore.get('isTabReloading'),
|
||||
]);
|
||||
|
||||
if (!isExtensionReloading) return sendResponse();
|
||||
|
||||
if (isTabReloading) {
|
||||
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
const tabToReload = tabs[0];
|
||||
|
||||
await DevStore.set('reloadTabId', tabToReload?.id);
|
||||
}
|
||||
chrome.runtime.reload();
|
||||
},
|
||||
};
|
||||
|
||||
export default hotReloadingHandler;
|
||||
20
src/pages/background/handler/tabManagementHandler.ts
Normal file
20
src/pages/background/handler/tabManagementHandler.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import TabManagementMessages from '@shared/messages/TabManagementMessages';
|
||||
import { MessageHandler } from 'chrome-extension-toolkit';
|
||||
import openNewTab from '../util/openNewTab';
|
||||
|
||||
const tabManagementHandler: MessageHandler<TabManagementMessages> = {
|
||||
getTabId({ sendResponse, sender }) {
|
||||
sendResponse(sender.tab?.id ?? -1);
|
||||
},
|
||||
openNewTab({ data, sender, sendResponse }) {
|
||||
const { url } = data;
|
||||
const nextIndex = sender.tab?.index ? sender.tab.index + 1 : undefined;
|
||||
openNewTab(url, nextIndex).then(sendResponse);
|
||||
},
|
||||
removeTab({ data, sendResponse }) {
|
||||
const { tabId } = data;
|
||||
chrome.tabs.remove(tabId).then(sendResponse);
|
||||
},
|
||||
};
|
||||
|
||||
export default tabManagementHandler;
|
||||
36
src/pages/background/handler/userScheduleHandler.ts
Normal file
36
src/pages/background/handler/userScheduleHandler.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { UserScheduleMessages } from '@shared/messages/UserScheduleMessages';
|
||||
import { Course } from '@shared/types/Course';
|
||||
import { MessageHandler } from 'chrome-extension-toolkit';
|
||||
import addCourse from '../lib/addCourse';
|
||||
import clearCourses from '../lib/clearCourses';
|
||||
import createSchedule from '../lib/createSchedule';
|
||||
import deleteSchedule from '../lib/deleteSchedule';
|
||||
import removeCourse from '../lib/removeCourse';
|
||||
import renameSchedule from '../lib/renameSchedule';
|
||||
import switchSchedule from '../lib/switchSchedule';
|
||||
|
||||
const userScheduleHandler: MessageHandler<UserScheduleMessages> = {
|
||||
addCourse({ data, sendResponse }) {
|
||||
addCourse(data.scheduleName, new Course(data.course)).then(sendResponse);
|
||||
},
|
||||
removeCourse({ data, sendResponse }) {
|
||||
removeCourse(data.scheduleName, new Course(data.course)).then(sendResponse);
|
||||
},
|
||||
clearCourses({ data, sendResponse }) {
|
||||
clearCourses(data.scheduleName).then(sendResponse);
|
||||
},
|
||||
switchSchedule({ data, sendResponse }) {
|
||||
switchSchedule(data.scheduleName).then(sendResponse);
|
||||
},
|
||||
createSchedule({ data, sendResponse }) {
|
||||
createSchedule(data.scheduleName).then(sendResponse);
|
||||
},
|
||||
deleteSchedule({ data, sendResponse }) {
|
||||
deleteSchedule(data.scheduleName).then(sendResponse);
|
||||
},
|
||||
renameSchedule({ data, sendResponse }) {
|
||||
renameSchedule(data.scheduleName, data.newName).then(sendResponse);
|
||||
},
|
||||
};
|
||||
|
||||
export default userScheduleHandler;
|
||||
Reference in New Issue
Block a user