1
1
import { getCoreContentText } from '../../utils/get-core-content-text'
2
2
import Browser from 'webextension-polyfill'
3
+ import { getUserConfig } from '../../config/index.mjs'
4
+ import { openUrl } from '../../utils/index.mjs'
3
5
4
6
export const config = {
5
7
newChat : {
@@ -16,27 +18,49 @@ export const config = {
16
18
} ,
17
19
openConversationPage : {
18
20
label : 'Open Conversation Page' ,
19
- action : async ( ) => {
20
- Browser . runtime . sendMessage ( {
21
- type : 'OPEN_URL' ,
22
- data : {
23
- url : Browser . runtime . getURL ( 'IndependentPanel.html' ) ,
24
- } ,
25
- } )
21
+ action : async ( fromBackground ) => {
22
+ console . debug ( 'action is from background' , fromBackground )
23
+ if ( fromBackground ) {
24
+ openUrl ( Browser . runtime . getURL ( 'IndependentPanel.html' ) )
25
+ } else {
26
+ Browser . runtime . sendMessage ( {
27
+ type : 'OPEN_URL' ,
28
+ data : {
29
+ url : Browser . runtime . getURL ( 'IndependentPanel.html' ) ,
30
+ } ,
31
+ } )
32
+ }
26
33
} ,
27
34
} ,
28
35
openConversationWindow : {
29
36
label : 'Open Conversation Window' ,
30
- action : async ( ) => {
31
- Browser . runtime . sendMessage ( {
32
- type : 'OPEN_CHAT_WINDOW' ,
33
- data : { } ,
34
- } )
37
+ action : async ( fromBackground ) => {
38
+ console . debug ( 'action is from background' , fromBackground )
39
+ if ( fromBackground ) {
40
+ const config = await getUserConfig ( )
41
+ const url = Browser . runtime . getURL ( 'IndependentPanel.html' )
42
+ const tabs = await Browser . tabs . query ( { url : url , windowType : 'popup' } )
43
+ if ( ! config . alwaysCreateNewConversationWindow && tabs . length > 0 )
44
+ await Browser . windows . update ( tabs [ 0 ] . windowId , { focused : true } )
45
+ else
46
+ await Browser . windows . create ( {
47
+ url : url ,
48
+ type : 'popup' ,
49
+ width : 500 ,
50
+ height : 650 ,
51
+ } )
52
+ } else {
53
+ Browser . runtime . sendMessage ( {
54
+ type : 'OPEN_CHAT_WINDOW' ,
55
+ data : { } ,
56
+ } )
57
+ }
35
58
} ,
36
59
} ,
37
60
closeAllChats : {
38
61
label : 'Close All Chats In This Page' ,
39
- action : async ( ) => {
62
+ action : async ( fromBackground ) => {
63
+ console . debug ( 'action is from background' , fromBackground )
40
64
Browser . tabs . query ( { active : true , currentWindow : true } ) . then ( ( tabs ) => {
41
65
Browser . tabs . sendMessage ( tabs [ 0 ] . id , {
42
66
type : 'CLOSE_CHATS' ,
0 commit comments