Skip to content

Commit 8bea70f

Browse files
committed
fix(background): refresh onClicked outside of onInstalled
1 parent 8ee84d4 commit 8bea70f

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/scripts/background/index.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { runtime } from '~/utils/browser/browser-runtime.utils';
88
import { storage } from '~/utils/browser/browser-storage.utils';
99
import { createTab } from '~/utils/browser/browser.utils';
1010

11-
export {};
12-
1311
console.debug('Background script started');
1412

1513
runtime?.onInstalled.addListener(async () => {
@@ -18,24 +16,24 @@ runtime?.onInstalled.addListener(async () => {
1816
await Promise.all(Object.values(ContextMenus).map(m => context!.create(m)));
1917

2018
console.debug('Context menus created');
19+
});
20+
21+
context?.onClicked.addListener(async info => {
22+
console.debug('Context menu event', info);
23+
24+
if (!info?.selectionText) return;
25+
await storage.local.set(RouterStorageKey.LastRoute, {
26+
name: Route.Search,
27+
query: { search: info.selectionText },
28+
} satisfies Partial<RouteLocationNormalized>);
29+
30+
if (info.menuItemId !== ContextMenuId.OpenInSideTrakt) return;
2131

22-
context.onClicked.addListener(async info => {
23-
console.debug('Context menu event', info);
24-
if (!context || !runtime) return;
25-
if (!info?.selectionText) return;
26-
await storage.local.set(RouterStorageKey.LastRoute, {
27-
name: Route.Search,
28-
query: { search: info.selectionText },
29-
} satisfies Partial<RouteLocationNormalized>);
30-
31-
if (info.menuItemId !== ContextMenuId.OpenInSideTrakt) return;
32-
33-
if (action?.openPopup) {
34-
await action.openPopup();
35-
} else {
36-
await createTab({
37-
url: runtime.getURL('views/options/index.html'),
38-
});
39-
}
40-
});
32+
if (action?.openPopup) {
33+
await action.openPopup();
34+
} else if (runtime) {
35+
await createTab({
36+
url: runtime.getURL('views/options/index.html'),
37+
});
38+
}
4139
});

0 commit comments

Comments
 (0)