refactor: Replace Webpack with Vite (#53)
This commit is contained in:
42
src/pages/background/util/hotReloadTab.ts
Normal file
42
src/pages/background/util/hotReloadTab.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { DevStore } from '@shared/storage/DevStore';
|
||||
|
||||
/**
|
||||
* A list of websites that we don't want to reload when the extension reloads (becuase it'd be hella annoying lmao)
|
||||
*/
|
||||
const HOT_RELOADING_WHITELIST = [
|
||||
'youtube.com',
|
||||
'twitch.tv',
|
||||
'github.dev',
|
||||
'figma.com',
|
||||
'netflix.com',
|
||||
'disneyplus.com',
|
||||
'hbomax.com',
|
||||
'spotify.com',
|
||||
'localhost:6006',
|
||||
'docs.google.com',
|
||||
'reddit.com',
|
||||
'gmail.com',
|
||||
'photopea.com',
|
||||
'chat.openai.com',
|
||||
];
|
||||
|
||||
/**
|
||||
* Reloads the tab that was open when the extension was reloaded
|
||||
* @returns a promise that resolves when the tab is reloaded
|
||||
*/
|
||||
export async function hotReloadTab(): Promise<void> {
|
||||
const [isTabReloading, reloadTabId] = await Promise.all([
|
||||
DevStore.get('isTabReloading'),
|
||||
DevStore.get('reloadTabId'),
|
||||
]);
|
||||
|
||||
if (!isTabReloading || !reloadTabId) return;
|
||||
|
||||
chrome.tabs.get(reloadTabId, tab => {
|
||||
if (!tab?.id) return;
|
||||
if (!tab.url) return;
|
||||
if (!HOT_RELOADING_WHITELIST.find(url => tab.url?.includes(url))) {
|
||||
chrome.tabs.reload(tab.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
25
src/pages/background/util/openDebugTab.ts
Normal file
25
src/pages/background/util/openDebugTab.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DevStore } from '@shared/storage/DevStore';
|
||||
|
||||
/**
|
||||
* Open the debug tab as the first tab
|
||||
*/
|
||||
export async function openDebugTab() {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const [debugTabId, wasDebugTabVisible] = await Promise.all([
|
||||
DevStore.get('debugTabId'),
|
||||
DevStore.get('wasDebugTabVisible'),
|
||||
]);
|
||||
|
||||
const isAlreadyOpen = await (await chrome.tabs.query({})).some(tab => tab.id === debugTabId);
|
||||
if (isAlreadyOpen) return;
|
||||
|
||||
const tab = await chrome.tabs.create({
|
||||
url: chrome.runtime.getURL('debug.html'),
|
||||
active: wasDebugTabVisible,
|
||||
pinned: true,
|
||||
index: 0,
|
||||
});
|
||||
|
||||
await DevStore.set('debugTabId', tab.id);
|
||||
}
|
||||
}
|
||||
10
src/pages/background/util/openNewTab.ts
Normal file
10
src/pages/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