using my boilerplate yuh

This commit is contained in:
Sriram Hariharan
2023-02-22 22:51:38 -06:00
parent 21d7056aae
commit bce2717088
91 changed files with 32400 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
/**
* This event is fired when any tab's url changes.
* This is useful for content scripts to know when SPA navigations occur.
* @param details
*/
export default function onHistoryStateUpdated(
details: chrome.webNavigation.WebNavigationTransitionCallbackDetails
): void {
const { tabId, url } = details;
// TODO: send a message to tab with tabId to reanalyze the page
}

View File

@@ -0,0 +1,26 @@
import { SECOND } from 'src/shared/util/time';
/**
* Called when the extension is first installed or synced onto a new machine
*/
export default async function onInstall() {
// set the uninstall url
chrome.runtime.setUninstallURL('https://www.google.com');
logOnInstallEvent();
}
/**
* making sure we are not sending duplicate install event for users that have synced browsers
* sync storage get's cleared on browser uninstall, so re-installing the browser will trigger the event
*/
function logOnInstallEvent() {
setTimeout(async () => {
const manifest = chrome.runtime.getManifest();
const INSTALL_KEY = `${manifest.short_name}-installed`;
const storage = await chrome.storage.sync.get(INSTALL_KEY);
if (!storage[INSTALL_KEY]) {
// TODO: send install event
await chrome.storage.sync.set({ [INSTALL_KEY]: true });
}
}, 5 * SECOND);
}

View File

@@ -0,0 +1,4 @@
/**
* This function is called when the user's browser opens for the first time
*/
export default function onNewChromeSession() {}

View File

@@ -0,0 +1,9 @@
import { openDebugTab } from '../util/openDebugTab';
/**
* Called whenever the background service worker comes alive
* (usually around 30 seconds to 5 minutes after it was last alive)
*/
export default function onServiceWorkerAlive() {
openDebugTab();
}

View File

@@ -0,0 +1,10 @@
import { hotReloadTab } from 'src/background/util/hotReloadTab';
/**
* Called when the extension is updated (or when the extension is reloaded in development mode)
*/
export default function onUpdate() {
if (process.env.NODE_ENV === 'development') {
hotReloadTab();
}
}