Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Apr 11, 2023
1 parent f460417 commit 162afd8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
44 changes: 32 additions & 12 deletions src/background/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,26 @@ Browser.runtime.onMessage.addListener(async (message) => {
})

Browser.commands.onCommand.addListener(async (command) => {
const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0]
const message = {
itemId: command,
selectionText: '',
useMenuPosition: false,
}
console.debug('command triggered', message)
if (command in menuConfig && menuConfig[command].action) menuConfig[command].action()
Browser.tabs.sendMessage(currentTab.id, {
type: 'CREATE_CHAT',
data: message,
})

if (command in menuConfig) {
if (menuConfig[command].action) {
menuConfig[command].action()
}

if (menuConfig[command].genPrompt) {
const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0]
Browser.tabs.sendMessage(currentTab.id, {
type: 'CREATE_CHAT',
data: message,
})
}
}
})

function refreshMenu() {
Expand Down Expand Up @@ -212,12 +220,24 @@ function refreshMenu() {
useMenuPosition: tab.id === currentTab.id,
}
console.debug('menu clicked', message)
if (message.itemId in menuConfig && menuConfig[message.itemId].action)
menuConfig[message.itemId].action()
Browser.tabs.sendMessage(currentTab.id, {
type: 'CREATE_CHAT',
data: message,
})

if (defaultConfig.selectionTools.includes(message.itemId)) {
Browser.tabs.sendMessage(currentTab.id, {
type: 'CREATE_CHAT',
data: message,
})
} else if (message.itemId in menuConfig) {
if (menuConfig[message.itemId].action) {
menuConfig[message.itemId].action()
}

if (menuConfig[message.itemId].genPrompt) {
Browser.tabs.sendMessage(currentTab.id, {
type: 'CREATE_CHAT',
data: message,
})
}
}
})
})
})
Expand Down
1 change: 0 additions & 1 deletion src/content-script/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ async function run() {
changeLanguage(lang)
})
Browser.runtime.onMessage.addListener(async (message) => {
console.log(message)
if (message.type === 'CHANGE_LANG') {
const data = message.data
changeLanguage(data.lang)
Expand Down

0 comments on commit 162afd8

Please sign in to comment.