bunch of refactor and styling changes, coming along nicely
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { MessageHandler } from 'chrome-extension-toolkit';
|
||||
import TabManagementMessages from 'src/shared/messages/TabManagementMessages';
|
||||
import openNewTab from '../util/openNewTab';
|
||||
|
||||
const tabManagementHandler: MessageHandler<TabManagementMessages> = {
|
||||
getTabId({ sendResponse, sender }) {
|
||||
sendResponse(sender.tab?.id ?? -1);
|
||||
},
|
||||
openNewTab({ data, sendResponse }) {
|
||||
openNewTab({ data, sender, sendResponse }) {
|
||||
const { url } = data;
|
||||
chrome.tabs.create({ url }).then(sendResponse);
|
||||
const nextIndex = sender.tab?.index ? sender.tab.index + 1 : undefined;
|
||||
openNewTab(url, nextIndex).then(sendResponse);
|
||||
},
|
||||
removeTab({ data, sendResponse }) {
|
||||
const { tabId } = data;
|
||||
|
||||
10
src/background/util/openNewTab.ts
Normal file
10
src/background/util/openNewTab.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* This is a helper function that opens a new tab in the current window, and focuses the window
|
||||
* @param tabIndex - the index of the tab to open the new tab at (optional)
|
||||
* @returns the tab that was opened
|
||||
*/
|
||||
export default async function openNewTab(url: string, tabIndex?: number): Promise<chrome.tabs.Tab> {
|
||||
const tab = await chrome.tabs.create({ url, index: tabIndex, active: true });
|
||||
await chrome.windows.update(tab.windowId, { focused: true });
|
||||
return tab;
|
||||
}
|
||||
Reference in New Issue
Block a user