raycast / extensions

Everything you need to extend Raycast.
https://developers.raycast.com
MIT License
5.38k stars 3.07k forks source link

[Easy Dictionary] Crash error #2394

Closed vin-mfvhn closed 2 years ago

vin-mfvhn commented 2 years ago

Extension – Easy Dictionary

Author: @tisfeng

Just cannot translate the text

Description

Open Search, then enter: "配賦元部門と配賦基準" -> Hit Enter -> Error happens

Error:

TypeError: Cannot read properties of undefined (reading 'webUrl')

Ho:easydict.js:73:290

---
70:         tell application "Shortcuts Events"
71:           run the shortcut named "${e}" with input "${i}"
72:         end tell
73:       `}var $0=e=>{let a=`eudic://dict/${e}`;(0,gi.execFile)("open",[a],i=>{i&&(console.log("error:",i),Pa.LocalStorage.removeItem(da),(0,Pa.showToast)({title:"Eudic is not installed.",style:Pa.Toast.Style.Failure}))})};var da="com.eusoft.freeeudic";function Ho(e){let[a,i]=(0,M0.useState)(!1),n=e.displayItem.queryWordInfo,t=nt("Google",n),o=nt("DeepL",n),r=nt("Youdao",n),p=nt("Eudic",n),s=r.webUrl&&n.isWord,m=p.webUrl&&n.isWord;e1(l=>{i(l)});function d(){new Ce().hideReleasePrompt().then(()=>{i(!1)})}return _jsx(U.ActionPanel,null,_jsx(U.ActionPanel.Section,null,a&&_jsx(W0,{title:"\u2728 New Version Released",onPush:d}),e.isInstalledEudic&&_jsx(U.Action,{icon:U.Icon.MagnifyingGlass,title:"Open in Eudic",onAction:()=>$0(n.word)}),_jsx(U.Action.CopyToClipboard,{onCopy:()=>{console.log("copy: ",e.displayItem.copyText)},title:"Copy Text",content:e.displayItem.copyText||""})),_jsx(U.ActionPanel.Section,{title:"Search Query Text Online"},o.webUrl.length&&_jsx(U.Action.OpenInBrowser,{icon:o.icon,title:o.title,url:o.webUrl}),_jsx(U.Action.OpenInBrowser,{icon:t.icon,title:t.title,url:t.webUrl}),s&&_jsx(U.Action.OpenInBrowser,{icon:r.icon,title:r.title,url:r.webUrl}),m&&_jsx(U.Action.OpenInBrowser,{icon:p.icon,title:p.title,url:p.webUrl})),_jsx(U.ActionPanel.Section,{title:"Play Text Audio"},_jsx(U.Action,{title:"Play Query Text",icon:Uo("black"),shortcut:{modifiers:["cmd"],key:"s"},onAction:()=>{console.log(`start play sound: ${n.word}`),$i(n)}}),_jsx(U.Action,{title:"Play Result Text",icon:Uo("black"),onAction:()=>{Ui(e.displayItem.copyText,n.toLanguage)}})),Y.isDisplayTargetTranslationLanguage&&_jsx(U.ActionPanel.Section,{title:"Target Language"},me.map(l=>{let u=l.youdaoLanguageId==="auto",c=l.youdaoLanguageId===n.fromLanguage,h=l.youdaoLanguageId===n.toLanguage;return u||c?null:_jsx(U.Action,{key:l.youdaoLanguageId,title:l.languageTitle,onAction:()=>e.onLanguageUpdate(l),icon:h?U.Icon.ArrowRight:U.Icon.Globe})})),_jsx(U.ActionPanel.Section,null,!a&&_jsx(W0,null),_jsx(W6,null),_jsx($6,null),_jsx($o,null)))}function $o(){let e=new Ce;return _jsx(U.Action.OpenInBrowser,{icon:U.Icon.QuestionMark,title:"Feedback",url:e.getIssueUrl()})}function $6(){return _jsx(U.Action,{icon:U.Icon.Gear,title:"Preferences",onAction:U.openCommandPreferences})}function W0(e){return _jsx(U.Action.Push,{icon:U.Icon.Stars,title:e.title||"Recent Updates",target:_jsx(l1,null),onPush:e.onPush})}function W6(){let e=new Ce;return _jsx(U.Action.OpenInBrowser,{icon:U.Icon.Eye,title:`Version: ${e.version}`,url:e.getCurrentReleaseTagUrl()})}function Uo(e){return{source:{light:"play.png",dark:"play.png"},tintColor:{light:e,dark:"lightgray"}}}function Y0(e){let a=U.Color.PrimaryText;switch(e){case"Translate":{a=U.Color.Red;break}case"Explanation":{a=U.Color.Blue;break}case"Web Translation":{a=U.Color.Yellow;break}case"Web Phrase":{a="teal";break}}let i={source:U.Icon.Dot,tintColor:a};return e==="Forms and Tenses"&&(i=U.Icon.Receipt),e in va&&(i=K0(e)),i}function K0(e){return{source:`${e}.png`,mask:U.Image.Mask.RoundedRectangle}}function G0(e,a){let i=[],n=[],t=[];return e==="Translate"&&(a.examTypes&&(i=[{icon:{source:U.Icon.Star,tintColor:U.Color.SecondaryText},tooltip:"Word included in the types of exam"},{text:a.examTypes?.join("  ")}],t=[...i]),a.phonetic&&(n=[{icon:Uo("gray"),tooltip:"Pronunciation"},{text:a.phonetic}],t=[...t,{text:" "},...n])),t}function nt(e,a){let i,n=`${e} Translate`;e in Ro&&(n=`${e} Dictionary`);let t=K0(e);switch(e.toString()){case"Google".toString():{i=Xs(a);break}case"DeepL".toString():{i=Js(a);break}case"Youdao".toString():{i=Qs(a);break}case"Eudic".toString():{i=Gs(a);break}}return i?{type:e,webUrl:i,icon:t,title:n}:void 0}var vi=M6();function Q0(e){let a=e.result,i=a.translation.map(m=>({type:"Youdao",text:m})),[n,t]=a.l.split("2"),o=a.basic?.["us-phonetic"];o=o?.split("; ")[1]||o;let r={word:a.query,phonetic:o||a.basic?.phonetic,speech:a.basic?.["us-speech"],fromLanguage:n,toLanguage:t,isWord:a.isWord,examTypes:a.basic?.exam_type,speechUrl:a.speakUrl},p;a.web&&(p=a.web[0]);let s=a.web?.slice(1);return{queryWordInfo:r,translationItems:i,explanations:a.basic?.explains,forms:a.basic?.wfs,webTranslation:p,webPhrases:s}}function X0(e,a){let i=a.result;return i?(e.translationItems.push({type:"DeepL",text:i.translations[0].text}),bi(e,vi)):e}function J0(e,a){let i=a.result;return i.translatedText?(e.translationItems.push({type:"Apple",text:i.translatedText}),bi(e,vi)):e}function Z0(e,a){let i=e.result;if(i?.trans_result){let n=i.trans_result.map(t=>t.dst).join(`
74: `);return a.translationItems.push({type:"Baidu",text:n}),bi(a,vi)}return a}function eu(e,a){let i=e.result;if(i){let n=i.TargetText;return a.translationItems.push({type:"Tencent",text:n}),bi(a,vi)}return a}function au(e,a){let i=e.result;return i?(a.translationItems.push({type:"Caiyun",text:i?.target.join(`
75: `)}),bi(a,vi)):a}function bi(e,a){let i=[];for(let t of e.translationItems){let o=a.indexOf(t.type.toString().toLowerCase());i[o]=t}let n=i.filter(t=>t);return e.translationItems=n,e}function M6(){let a=["DeepL","Apple","Baidu","Tencent","Youdao","Caiyun"].map(o=>o.toString().toLowerCase()),i=[],n=Y.translationDisplayOrder.toLowerCase().split(",");if(n.length>0)for(let o of n)o=o.trim(),a.includes(o)&&(i.push(o),a.splice(a.indexOf(o),1));return[...i,...a]}function iu(e){let a=[];if(!e)return a;let i=Ja(e);for(let[p,s]of e.translationItems.entries()){let m=i?s.type:"Translate",d="Translate".toString(),l=`${s.type.toString()} Translate`;i&&(d=l,l="");let u=s.text.split(`
76: `).join(" "),c=e.queryWordInfo.phonetic?`[${e.queryWordInfo.phonetic}]`:void 0,b=c||e.queryWordInfo.examTypes?e.queryWordInfo.word:void 0;if(a.push({type:m,sectionTitle:d,items:[{key:u+p,title:` ${u}`,subtitle:b,tooltip:l,copyText:u,queryWordInfo:e.queryWordInfo,phonetic:c,speech:e.queryWordInfo.speech,examTypes:e.queryWordInfo.examTypes,translationMarkdown:Y6(m,e)}]}),!Ja)break}let n=!1,t="Details";e.explanations?.forEach((p,s)=>{a.push({type:"Explanation",sectionTitle:n?void 0:t,items:[{key:p+s,title:p,queryWordInfo:e.queryWordInfo,tooltip:"Explanation",copyText:p}]}),n=!0});let r=e.forms?.map(p=>p.wf?.name+" "+p.wf?.value)?.join("   ")||"";if(r.length&&(a.push({type:"Forms and Tenses",sectionTitle:n?void 0:t,items:[{key:r,title:"",queryWordInfo:e.queryWordInfo,tooltip:"Forms and Tenses",subtitle:`[ ${r} ]`,copyText:r}]}),n=!0),e.webTranslation){let p=e.webTranslation?.key,s=e.webTranslation.value.join("\uFF1B"),m=`${p} ${s}`;a.push({type:"Web Translation",sectionTitle:n?void 0:t,items:[{key:m,title:p,queryWordInfo:e.queryWordInfo,tooltip:"Web Translation",subtitle:s,copyText:m}]}),n=!0}return e.webPhrases?.forEach((p,s)=>{let m=p.key,d=p.value.join("\uFF1B"),l=`${m} ${d}`;a.push({type:"Web Phrase",sectionTitle:n?void 0:t,items:[{key:l+s,title:m,queryWordInfo:e.queryWordInfo,tooltip:"Web Phrase",subtitle:d,copyText:l}]}),n=!0}),a}function Y6(e,a){let i=[];for(let n of a.translationItems){let t=K6(n.type,n.text);i.push({type:n.type,text:t})}for(let n=0;n<i.length;n++)if(i[n].type===e){let t=i[n];i.splice(n,1),i.unshift(t);break}return i.map(n=>n.text).join(`
---

    at ray-list-item
Ur:index.js:13:34932
    at ray-list-section
bn:index.js:13:32491
    at F
    at ray-list
He:index.js:13:36230
G6:easydict.js:83:82
Ut:index.js:5:2458
    at ray-navigation-stack
Cr:index.js:5:2088
    at Suspense
wr:index.js:4:714
    at ray-root
vi:index.js:5:2867

Steps To Reproduce

1. 2.

The current behavior

The expected behavior

Raycast version

Version: 1.38.2

tisfeng commented 2 years ago

@vin-mfvhn Thank you for your feedback, this bug should have been fixed in the latest version, you can try it.

https://github.com/tisfeng/Raycast-Easydict/releases/tag/1.4.0

tisfeng commented 2 years ago

I have submitted a PR to the store, and waiting for review https://github.com/raycast/extensions/pull/2359

vin-mfvhn commented 2 years ago

Thank you! I will checkit