diff --git a/src/background/commands.mjs b/src/background/commands.mjs index 9264910..e6b3b3e 100644 --- a/src/background/commands.mjs +++ b/src/background/commands.mjs @@ -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) { diff --git a/src/background/menus.mjs b/src/background/menus.mjs index 19a24cf..ad027ee 100644 --- a/src/background/menus.mjs +++ b/src/background/menus.mjs @@ -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) { diff --git a/src/content-script/menu-tools/index.mjs b/src/content-script/menu-tools/index.mjs index 6bb15df..c46e523 100644 --- a/src/content-script/menu-tools/index.mjs +++ b/src/content-script/menu-tools/index.mjs @@ -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', diff --git a/src/popup/index.jsx b/src/popup/index.jsx index 50d5c01..9eefdaa 100644 --- a/src/popup/index.jsx +++ b/src/popup/index.jsx @@ -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) {