Skip to content

Commit

Permalink
Fix outbound and selection translation
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmervdl committed Aug 16, 2023
1 parent f085d47 commit 1cb7f07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/background/background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,14 @@ compat.runtime.onInstalled.addListener(() => {
compat.contextMenus.onClicked.addListener(async ({menuItemId, frameId}, tab) => {
// First sanity check whether we know from and to languages
// (and it isn't the same by accident)
const {from, to} = session.get(tab.id).get({from, to});
const {from, to} = await session.get(tab.id).get({from: undefined, to: undefined});

// Send the appropriate message down to the content script of the
// tab we just clicked inside of.
switch (menuItemId) {
case 'translate-selection':
if (from === undefined || to === undefined || from === to) {
compat.action.openPopup();
break;
}
if (from === undefined || to === undefined || from === to)
break; // Euh, what to do? Can't trigger a popup anymore

compat.tabs.sendMessage(tab.id, {
command: 'TranslateSelection',
Expand Down
6 changes: 3 additions & 3 deletions src/content/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ const selectionTranslation = new SelectionTranslation({

const outboundTranslation = new OutboundTranslation(new class ErzatsTranslatorBacking {
constructor() {
// TranslatorBacking that mimics just enough for
// LatencyOptimisedTranslator to do its work.
// TranslatorBacking that is really just a proxy, but mimics just enough
// for LatencyOptimisedTranslator to do its work.
const backing = {
async loadWorker() {
// Pending translation promises.
Expand All @@ -146,7 +146,7 @@ const outboundTranslation = new OutboundTranslation(new class ErzatsTranslatorBa
port.onMessage.addListener(callback);
})

handler.on('TranslateResponse', ({id, target, error}) => {
handler.on('TranslateResponse', ({request: {user: {id}}, target, error}) => {
const {request, accept, reject} = pending.get(id);
pending.delete(id);

Expand Down
5 changes: 4 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
"resources": [
"assets/fonts/FlowBlock-Regular.woff2",
"assets/fonts/FlowCircular-Regular.woff2",
"assets/fonts/FlowRounded-Regular.woff2"
"assets/fonts/FlowRounded-Regular.woff2",
"OutboundTranslation.css",
"InPageTranslation.css",
"SelectionTranslation.css"
]
}
],
Expand Down

0 comments on commit 1cb7f07

Please sign in to comment.