chore: menu action source

This commit is contained in:
josc146
2023-05-13 17:09:58 +08:00
parent 9b2c8d3d33
commit 39dc01bbcb
4 changed files with 40 additions and 16 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ export function registerCommands() {
if (command in menuConfig) {
if (menuConfig[command].action) {
menuConfig[command].action()
menuConfig[command].action(true)
}
if (menuConfig[command].genPrompt) {
+1 -1
View File
@@ -57,7 +57,7 @@ export function refreshMenu() {
})
} else if (message.itemId in menuConfig) {
if (menuConfig[message.itemId].action) {
menuConfig[message.itemId].action()
menuConfig[message.itemId].action(true)
}
if (menuConfig[message.itemId].genPrompt) {
+37 -13
View File
@@ -1,5 +1,7 @@
import { getCoreContentText } from '../../utils/get-core-content-text'
import Browser from 'webextension-polyfill'
import { getUserConfig } from '../../config/index.mjs'
import { openUrl } from '../../utils/index.mjs'
export const config = {
newChat: {
@@ -16,27 +18,49 @@ export const config = {
},
openConversationPage: {
label: 'Open Conversation Page',
action: async () => {
Browser.runtime.sendMessage({
type: 'OPEN_URL',
data: {
url: Browser.runtime.getURL('IndependentPanel.html'),
},
})
action: async (fromBackground) => {
console.debug('action is from background', fromBackground)
if (fromBackground) {
openUrl(Browser.runtime.getURL('IndependentPanel.html'))
} else {
Browser.runtime.sendMessage({
type: 'OPEN_URL',
data: {
url: Browser.runtime.getURL('IndependentPanel.html'),
},
})
}
},
},
openConversationWindow: {
label: 'Open Conversation Window',
action: async () => {
Browser.runtime.sendMessage({
type: 'OPEN_CHAT_WINDOW',
data: {},
})
action: async (fromBackground) => {
console.debug('action is from background', fromBackground)
if (fromBackground) {
const config = await getUserConfig()
const url = Browser.runtime.getURL('IndependentPanel.html')
const tabs = await Browser.tabs.query({ url: url, windowType: 'popup' })
if (!config.alwaysCreateNewConversationWindow && tabs.length > 0)
await Browser.windows.update(tabs[0].windowId, { focused: true })
else
await Browser.windows.create({
url: url,
type: 'popup',
width: 500,
height: 650,
})
} else {
Browser.runtime.sendMessage({
type: 'OPEN_CHAT_WINDOW',
data: {},
})
}
},
},
closeAllChats: {
label: 'Close All Chats In This Page',
action: async () => {
action: async (fromBackground) => {
console.debug('action is from background', fromBackground)
Browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
Browser.tabs.sendMessage(tabs[0].id, {
type: 'CLOSE_CHATS',
+1 -1
View File
@@ -18,7 +18,7 @@ getUserConfig().then(async (config) => {
if (config.clickIconAction in menuConfig) {
if (menuConfig[config.clickIconAction].action) {
menuConfig[config.clickIconAction].action()
menuConfig[config.clickIconAction].action(false)
}
if (menuConfig[config.clickIconAction].genPrompt) {