Skip to content

Commit

Permalink
invoke popup on install
Browse files Browse the repository at this point in the history
  • Loading branch information
nl32 committed Apr 11, 2024
1 parent 4e84fc9 commit b84b6bd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Storage } from '@plasmohq/storage';

import { CourseHeader, listenForTableChange, scrapeCourseData } from '~content';
import { neededOrigins } from '~data/config';

export interface ShowCourseTabPayload {
header: CourseHeader;
Expand Down Expand Up @@ -93,6 +94,28 @@ realBrowser.tabs.onActivated.addListener(async () => {
}
});

realBrowser.runtime.onInstalled.addListener(async () => {
console.log('hey from install listener');
const currentPermissions: { permissions: string[]; origins: string[] } =
await realBrowser.permissions.getAll();
console.log(`current permissions: ${currentPermissions.origins}`);
if (
neededOrigins.filter(
(origin) => !currentPermissions.origins.includes(origin),
).length !== 0
) {
console.log('opening permission request');
const popupURL = await realBrowser.runtime.getURL('tabs/permissions.html');
console.log(popupURL);
realBrowser.windows.create({
url: popupURL,
type: 'popup',
width: 550,
height: 250,
});
}
});

export async function getScrapedCourseData() {
const cachedTabUrl: string = await storage.get('courseTabUrl');
const currentTabUrl: string = (await getCurrentTab()).url;
Expand Down

0 comments on commit b84b6bd

Please sign in to comment.