Skip to content

Commit 39dc01b

Browse files
committed
chore: menu action source
1 parent 9b2c8d3 commit 39dc01b

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

src/background/commands.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function registerCommands() {
1212

1313
if (command in menuConfig) {
1414
if (menuConfig[command].action) {
15-
menuConfig[command].action()
15+
menuConfig[command].action(true)
1616
}
1717

1818
if (menuConfig[command].genPrompt) {

src/background/menus.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function refreshMenu() {
5757
})
5858
} else if (message.itemId in menuConfig) {
5959
if (menuConfig[message.itemId].action) {
60-
menuConfig[message.itemId].action()
60+
menuConfig[message.itemId].action(true)
6161
}
6262

6363
if (menuConfig[message.itemId].genPrompt) {

src/content-script/menu-tools/index.mjs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { getCoreContentText } from '../../utils/get-core-content-text'
22
import Browser from 'webextension-polyfill'
3+
import { getUserConfig } from '../../config/index.mjs'
4+
import { openUrl } from '../../utils/index.mjs'
35

46
export const config = {
57
newChat: {
@@ -16,27 +18,49 @@ export const config = {
1618
},
1719
openConversationPage: {
1820
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+
}
2633
},
2734
},
2835
openConversationWindow: {
2936
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+
}
3558
},
3659
},
3760
closeAllChats: {
3861
label: 'Close All Chats In This Page',
39-
action: async () => {
62+
action: async (fromBackground) => {
63+
console.debug('action is from background', fromBackground)
4064
Browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
4165
Browser.tabs.sendMessage(tabs[0].id, {
4266
type: 'CLOSE_CHATS',

src/popup/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ getUserConfig().then(async (config) => {
1818

1919
if (config.clickIconAction in menuConfig) {
2020
if (menuConfig[config.clickIconAction].action) {
21-
menuConfig[config.clickIconAction].action()
21+
menuConfig[config.clickIconAction].action(false)
2222
}
2323

2424
if (menuConfig[config.clickIconAction].genPrompt) {

0 commit comments

Comments
 (0)