diff --git a/enjoy/src/main/window.ts b/enjoy/src/main/window.ts index c2dd7195..5e29d3d6 100644 --- a/enjoy/src/main/window.ts +++ b/enjoy/src/main/window.ts @@ -196,7 +196,12 @@ main.init = () => { }); logger.debug("will-navigate", detail.url); - if (!navigatable) { + if ( + !navigatable || + detail.url.startsWith( + `${process.env.WEB_API_URL || WEB_API_URL}/oauth` + ) + ) { logger.debug("prevent navigation", detail.url); detail.preventDefault(); } diff --git a/enjoy/src/renderer/components/lookup-result.tsx b/enjoy/src/renderer/components/lookup-result.tsx index 71d093ea..0cd454ca 100644 --- a/enjoy/src/renderer/components/lookup-result.tsx +++ b/enjoy/src/renderer/components/lookup-result.tsx @@ -14,14 +14,14 @@ export const LookupResult = (props: { }) => { const { word, context, sourceId, sourceType, onResult } = props; const [result, setResult] = useState(); - const [loading, setLoading] = useState(true); + const [loading, setLoading] = useState(false); if (!word) return null; const { lookupWord } = useAiCommand(); const processLookup = async () => { if (!word) return; - if (!loading) return; + if (loading) return; setLoading(true); lookupWord({ @@ -31,8 +31,10 @@ export const LookupResult = (props: { sourceType, }) .then((lookup) => { - setResult(lookup); - onResult && onResult(lookup.meaning); + if (lookup?.meaning) { + setResult(lookup); + onResult && onResult(lookup.meaning); + } }) .finally(() => { setLoading(false); diff --git a/enjoy/src/renderer/hooks/useAiCommand.tsx b/enjoy/src/renderer/hooks/useAiCommand.tsx index 3e45594a..0ea840be 100644 --- a/enjoy/src/renderer/hooks/useAiCommand.tsx +++ b/enjoy/src/renderer/hooks/useAiCommand.tsx @@ -36,7 +36,7 @@ export const useAiCommand = () => { return lookup; } - lookupCommand( + const res = await lookupCommand( { word, context, @@ -47,23 +47,15 @@ export const useAiCommand = () => { modelName: currentEngine.model, baseUrl: currentEngine.baseUrl, } - ) - .then((res) => { - if (res.context_translation?.trim()) { - webApi - .updateLookup(lookup.id, { - meaning: res, - sourceId, - sourceType, - }) - .then((lookup) => { - return lookup; - }); - } - }) - .catch((err) => { - toast.error(`${t("lookupFailed")}: ${err.message}`); + ); + + if (res.context_translation?.trim()) { + return webApi.updateLookup(lookup.id, { + meaning: res, + sourceId, + sourceType, }); + } }; const extractStory = async (story: StoryType) => {