using my boilerplate yuh
This commit is contained in:
6
src/shared/messages/BrowserActionMessages.ts
Normal file
6
src/shared/messages/BrowserActionMessages.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export default interface BrowserActionMessages {
|
||||
/** make it so that clicking the browser action will open the popup.html */
|
||||
enableBrowserAction: () => void;
|
||||
/** make it so that clicking the browser action will respond to interactions from the content script */
|
||||
disableBrowserAction: () => void;
|
||||
}
|
||||
3
src/shared/messages/HotReloadingMessages.ts
Normal file
3
src/shared/messages/HotReloadingMessages.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default interface HotReloadingMessages {
|
||||
reloadExtension: () => void;
|
||||
}
|
||||
21
src/shared/messages/TabManagementMessages.ts
Normal file
21
src/shared/messages/TabManagementMessages.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Messages for managing the user's open tabs list
|
||||
*/
|
||||
export default interface TabManagementMessages {
|
||||
/**
|
||||
* Opens a new tab with the given URL
|
||||
* @param data The URL to open
|
||||
*/
|
||||
openNewTab: (data: { url: string }) => chrome.tabs.Tab;
|
||||
/**
|
||||
* Gets the ID of the current tab (the tab that sent the message)
|
||||
* @returns The ID of the current tab
|
||||
*/
|
||||
getTabId: () => number;
|
||||
/**
|
||||
* Removes the tab with the given ID
|
||||
* @param data The ID of the tab to remove
|
||||
* @returns The ID of the tab that was removed
|
||||
*/
|
||||
removeTab: (data: { tabId: number }) => void;
|
||||
}
|
||||
6
src/shared/messages/TabMessages.ts
Normal file
6
src/shared/messages/TabMessages.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* This is a type with all the message definitions that can be sent TO specific tabs
|
||||
*/
|
||||
export default interface TAB_MESSAGES {
|
||||
reAnalyzePage: (data: { url: string }) => void;
|
||||
}
|
||||
21
src/shared/messages/index.ts
Normal file
21
src/shared/messages/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createMessenger } from 'chrome-extension-toolkit';
|
||||
import TAB_MESSAGES from './TabMessages';
|
||||
import BrowserActionMessages from './BrowserActionMessages';
|
||||
import HotReloadingMessages from './HotReloadingMessages';
|
||||
import TabManagementMessages from './TabManagementMessages';
|
||||
|
||||
/**
|
||||
* This is a type with all the message definitions that can be sent TO the background script
|
||||
*/
|
||||
export type BACKGROUND_MESSAGES = BrowserActionMessages & TabManagementMessages & HotReloadingMessages;
|
||||
|
||||
/**
|
||||
* A utility object that can be used to send type-safe messages to the background script
|
||||
*/
|
||||
export const bMessenger = 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');
|
||||
Reference in New Issue
Block a user