@@ -8,8 +8,6 @@ import { runtime } from '~/utils/browser/browser-runtime.utils';
8
8
import { storage } from '~/utils/browser/browser-storage.utils' ;
9
9
import { createTab } from '~/utils/browser/browser.utils' ;
10
10
11
- export { } ;
12
-
13
11
console . debug ( 'Background script started' ) ;
14
12
15
13
runtime ?. onInstalled . addListener ( async ( ) => {
@@ -18,24 +16,24 @@ runtime?.onInstalled.addListener(async () => {
18
16
await Promise . all ( Object . values ( ContextMenus ) . map ( m => context ! . create ( m ) ) ) ;
19
17
20
18
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 ;
21
31
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
+ }
41
39
} ) ;
0 commit comments