raycast / extensions

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

[Dash]: Extensions doesn't show an error properly if I don't have the app installed #2460

Closed mattisssa closed 2 years ago

mattisssa commented 2 years ago

Extension – Dash

Author: @RSO

Description

Can we handle this more properly and show a failure toast in the case I don't have Dash app installed?

Error:

CleanShot 2022-08-02 at 16 59 58@2x

Error: Dash.app not found

index.js:27:9955

---
24: `.charCodeAt(),r=typeof e=="string"?"\r":"\r".charCodeAt();return e[e.length-1]===t&&(e=e.slice(0,-1)),e[e.length-1]===r&&(e=e.slice(0,-1)),e}var Wt=Y(require("node:process"),1),bt=Y(require("node:path"),1),Ba=Y(require("node:url"),1);function wr(e={}){let{env:t=process.env,platform:r=process.platform}=e;return r!=="win32"?"PATH":Object.keys(t).reverse().find(n=>n.toUpperCase()==="PATH")||"Path"}function Rg(e={}){let{cwd:t=Wt.default.cwd(),path:r=Wt.default.env[wr()],execPath:n=Wt.default.execPath}=e,i,s=t instanceof URL?Ba.default.fileURLToPath(t):t,o=bt.default.resolve(s),a=[];for(;i!==o;)a.push(bt.default.join(o,"node_modules/.bin")),i=o,o=bt.default.resolve(o,"..");return a.push(bt.default.resolve(s,n,"..")),[...a,r].join(bt.default.delimiter)}function Ga(r={}){var n=r,{env:e=Wt.default.env}=n,t=mt(n,["env"]);e=A({},e);let i=wr({env:e});return t.path=e[i],e[i]=Rg(t),e}var Tg=(e,t,r,n)=>{if(r==="length"||r==="prototype"||r==="arguments"||r==="caller")return;let i=Object.getOwnPropertyDescriptor(e,r),s=Object.getOwnPropertyDescriptor(t,r);!qg(i,s)&&n||Object.defineProperty(e,r,s)},qg=function(e,t){return e===void 0||e.configurable||e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable&&(e.writable||e.value===t.value)},Pg=(e,t)=>{let r=Object.getPrototypeOf(t);r!==Object.getPrototypeOf(e)&&Object.setPrototypeOf(e,r)},Og=(e,t)=>`/* Wrapped ${e}*/
25: ${t}`,Cg=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),kg=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),Ng=(e,t,r)=>{let n=r===""?"":`with ${r.trim()}() `,i=Og.bind(null,n,t.toString());Object.defineProperty(i,"name",kg),Object.defineProperty(e,"toString",F(A({},Cg),{value:i}))};function ei(e,t,{ignoreNonConfigurable:r=!1}={}){let{name:n}=e;for(let i of Reflect.ownKeys(t))Tg(e,t,i,r);return Pg(e,t),Ng(e,t,n),e}var _r=new WeakMap,$a=(e,t={})=>{if(typeof e!="function")throw new TypeError("Expected a function");let r,n=0,i=e.displayName||e.name||"<anonymous>",s=function(...o){if(_r.set(s,++n),n===1)r=e.apply(this,o),e=null;else if(t.throw===!0)throw new Error(`Function \`${i}\` can only be called once`);return r};return ei(s,e),_r.set(s,n),s};$a.callCount=e=>{if(!_r.has(e))throw new Error(`The given function \`${e.name}\` is not wrapped by the \`onetime\` package`);return _r.get(e)};var ja=$a;var Ka=require("os");var Ha=function(){let e=ti-Ua+1;return Array.from({length:e},Lg)},Lg=function(e,t){return{name:`SIGRT${t+1}`,number:Ua+t,action:"terminate",description:"Application-specific signal (realtime)",standard:"posix"}},Ua=34,ti=64;var Wa=require("os");var Va=[{name:"SIGHUP",number:1,action:"terminate",description:"Terminal closed",standard:"posix"},{name:"SIGINT",number:2,action:"terminate",description:"User interruption with CTRL-C",standard:"ansi"},{name:"SIGQUIT",number:3,action:"core",description:"User interruption with CTRL-\\",standard:"posix"},{name:"SIGILL",number:4,action:"core",description:"Invalid machine instruction",standard:"ansi"},{name:"SIGTRAP",number:5,action:"core",description:"Debugger breakpoint",standard:"posix"},{name:"SIGABRT",number:6,action:"core",description:"Aborted",standard:"ansi"},{name:"SIGIOT",number:6,action:"core",description:"Aborted",standard:"bsd"},{name:"SIGBUS",number:7,action:"core",description:"Bus error due to misaligned, non-existing address or paging error",standard:"bsd"},{name:"SIGEMT",number:7,action:"terminate",description:"Command should be emulated but is not implemented",standard:"other"},{name:"SIGFPE",number:8,action:"core",description:"Floating point arithmetic error",standard:"ansi"},{name:"SIGKILL",number:9,action:"terminate",description:"Forced termination",standard:"posix",forced:!0},{name:"SIGUSR1",number:10,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGSEGV",number:11,action:"core",description:"Segmentation fault",standard:"ansi"},{name:"SIGUSR2",number:12,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGPIPE",number:13,action:"terminate",description:"Broken pipe or socket",standard:"posix"},{name:"SIGALRM",number:14,action:"terminate",description:"Timeout or timer",standard:"posix"},{name:"SIGTERM",number:15,action:"terminate",description:"Termination",standard:"ansi"},{name:"SIGSTKFLT",number:16,action:"terminate",description:"Stack is empty or overflowed",standard:"other"},{name:"SIGCHLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"posix"},{name:"SIGCLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"other"},{name:"SIGCONT",number:18,action:"unpause",description:"Unpaused",standard:"posix",forced:!0},{name:"SIGSTOP",number:19,action:"pause",description:"Paused",standard:"posix",forced:!0},{name:"SIGTSTP",number:20,action:"pause",description:'Paused using CTRL-Z or "suspend"',standard:"posix"},{name:"SIGTTIN",number:21,action:"pause",description:"Background process cannot read terminal input",standard:"posix"},{name:"SIGBREAK",number:21,action:"terminate",description:"User interruption with CTRL-BREAK",standard:"other"},{name:"SIGTTOU",number:22,action:"pause",description:"Background process cannot write to terminal output",standard:"posix"},{name:"SIGURG",number:23,action:"ignore",description:"Socket received out-of-band data",standard:"bsd"},{name:"SIGXCPU",number:24,action:"core",description:"Process timed out",standard:"bsd"},{name:"SIGXFSZ",number:25,action:"core",description:"File too big",standard:"bsd"},{name:"SIGVTALRM",number:26,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGPROF",number:27,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGWINCH",number:28,action:"ignore",description:"Terminal window size changed",standard:"bsd"},{name:"SIGIO",number:29,action:"terminate",description:"I/O is available",standard:"other"},{name:"SIGPOLL",number:29,action:"terminate",description:"Watched event",standard:"other"},{name:"SIGINFO",number:29,action:"ignore",description:"Request for process information",standard:"other"},{name:"SIGPWR",number:30,action:"terminate",description:"Device running out of power",standard:"systemv"},{name:"SIGSYS",number:31,action:"core",description:"Invalid system call",standard:"other"},{name:"SIGUNUSED",number:31,action:"terminate",description:"Invalid system call",standard:"other"}];var ri=function(){let e=Ha();return[...Va,...e].map(Ig)},Ig=function({name:e,number:t,description:r,action:n,forced:i=!1,standard:s}){let{signals:{[e]:o}}=Wa.constants,a=o!==void 0;return{name:e,number:a?o:t,description:r,supported:a,action:n,forced:i,standard:s}};var Dg=function(){return ri().reduce(Fg,{})},Fg=function(e,{name:t,number:r,description:n,supported:i,action:s,forced:o,standard:a}){return F(A({},e),{[t]:{name:t,number:r,description:n,supported:i,action:s,forced:o,standard:a}})},za=Dg(),Mg=function(){let e=ri(),t=64+1,r=Array.from({length:t},(n,i)=>Bg(i,e));return Object.assign({},...r)},Bg=function(e,t){let r=Gg(e,t);if(r===void 0)return{};let{name:n,description:i,supported:s,action:o,forced:a,standard:c}=r;return{[e]:{name:n,number:e,description:i,supported:s,action:o,forced:a,standard:c}}},Gg=function(e,t){let r=t.find(({name:n})=>Ka.constants.signals[n]===e);return r!==void 0?r:t.find(n=>n.number===e)},NR=Mg();var $g=({timedOut:e,timeout:t,errorCode:r,signal:n,signalDescription:i,exitCode:s,isCanceled:o})=>e?`timed out after ${t} milliseconds`:o?"was canceled":r!==void 0?`failed with ${r}`:n!==void 0?`was killed with ${n} (${i})`:s!==void 0?`failed with exit code ${s}`:"failed",ni=({stdout:e,stderr:t,all:r,error:n,signal:i,exitCode:s,command:o,escapedCommand:a,timedOut:c,isCanceled:l,killed:u,parsed:{options:{timeout:d}}})=>{s=s===null?void 0:s,i=i===null?void 0:i;let f=i===void 0?void 0:za[i].description,h=n&&n.code,g=`Command ${$g({timedOut:c,timeout:d,errorCode:h,signal:i,signalDescription:f,exitCode:s,isCanceled:l})}: ${o}`,v=Object.prototype.toString.call(n)==="[object Error]",E=v?`${g}
26: ${n.message}`:g,_=[E,t,e].filter(Boolean).join(`
27: `);return v?(n.originalMessage=n.message,n.message=_):n=new Error(_),n.shortMessage=E,n.command=o,n.escapedCommand=a,n.exitCode=s,n.signal=i,n.signalDescription=f,n.stdout=e,n.stderr=t,r!==void 0&&(n.all=r),"bufferedData"in n&&delete n.bufferedData,n.failed=!0,n.timedOut=Boolean(c),n.isCanceled=l,n.killed=u&&!c,n};var Ar=["stdin","stdout","stderr"],jg=e=>Ar.some(t=>e[t]!==void 0),Xa=e=>{if(!e)return;let{stdio:t}=e;if(t===void 0)return Ar.map(n=>e[n]);if(jg(e))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${Ar.map(n=>`\`${n}\``).join(", ")}`);if(typeof t=="string")return t;if(!Array.isArray(t))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof t}\``);let r=Math.max(t.length,Ar.length);return Array.from({length:r},(n,i)=>t[i])};var tc=Y(require("node:os"),1),rc=Y(oi(),1),Hg=1e3*5,nc=(e,t="SIGTERM",r={})=>{let n=e(t);return Ug(e,t,r,n),n},Ug=(e,t,r,n)=>{if(!Vg(t,r,n))return;let i=Kg(r),s=setTimeout(()=>{e("SIGKILL")},i);s.unref&&s.unref()},Vg=(e,{forceKillAfterTimeout:t},r)=>Wg(e)&&t!==!1&&r,Wg=e=>e===tc.default.constants.signals.SIGTERM||typeof e=="string"&&e.toUpperCase()==="SIGTERM",Kg=({forceKillAfterTimeout:e=!0})=>{if(e===!0)return Hg;if(!Number.isFinite(e)||e<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`);return e},ic=(e,t)=>{e.kill()&&(t.isCanceled=!0)},zg=(e,t,r)=>{e.kill(t),r(Object.assign(new Error("Timed out"),{timedOut:!0,signal:t}))},sc=(e,{timeout:t,killSignal:r="SIGTERM"},n)=>{if(t===0||t===void 0)return n;let i,s=new Promise((a,c)=>{i=setTimeout(()=>{zg(e,r,c)},t)}),o=n.finally(()=>{clearTimeout(i)});return Promise.race([s,o])},oc=({timeout:e})=>{if(e!==void 0&&(!Number.isFinite(e)||e<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`)},ac=async(e,{cleanup:t,detached:r},n)=>{if(!t||r)return n;let i=(0,rc.default)(()=>{e.kill()});return n.finally(()=>{i()})};function cc(e){return e!==null&&typeof e=="object"&&typeof e.pipe=="function"}var di=Y(fc(),1),pc=Y(ui(),1),hc=(e,t)=>{t===void 0||e.stdin===void 0||(cc(t)?t.pipe(e.stdin):e.stdin.end(t))},mc=(e,{all:t})=>{if(!t||!e.stdout&&!e.stderr)return;let r=(0,pc.default)();return e.stdout&&r.add(e.stdout),e.stderr&&r.add(e.stderr),r},li=async(e,t)=>{if(!!e){e.destroy();try{return await t}catch(r){return r.bufferedData}}},fi=(e,{encoding:t,buffer:r,maxBuffer:n})=>{if(!(!e||!r))return t?(0,di.default)(e,{encoding:t,maxBuffer:n}):di.default.buffer(e,{maxBuffer:n})},gc=async({stdout:e,stderr:t,all:r},{encoding:n,buffer:i,maxBuffer:s},o)=>{let a=fi(e,{encoding:n,buffer:i,maxBuffer:s}),c=fi(t,{encoding:n,buffer:i,maxBuffer:s}),l=fi(r,{encoding:n,buffer:i,maxBuffer:s*2});try{return await Promise.all([o,a,c,l])}catch(u){return Promise.all([{error:u,signal:u.signal,timedOut:u.timedOut},li(e,a),li(t,c),li(r,l)])}};var ry=(async()=>{})().constructor.prototype,ny=["then","catch","finally"].map(e=>[e,Reflect.getOwnPropertyDescriptor(ry,e)]),pi=(e,t)=>{for(let[r,n]of ny){let i=typeof t=="function"?(...s)=>Reflect.apply(n.value,t(),s):n.value.bind(t);Reflect.defineProperty(e,r,F(A({},n),{value:i}))}return e},yc=e=>new Promise((t,r)=>{e.on("exit",(n,i)=>{t({exitCode:n,signal:i})}),e.on("error",n=>{r(n)}),e.stdin&&e.stdin.on("error",n=>{r(n)})});var bc=(e,t=[])=>Array.isArray(t)?[e,...t]:[e],iy=/^[\w.-]+$/,sy=/"/g,oy=e=>typeof e!="string"||iy.test(e)?e:`"${e.replace(sy,'\\"')}"`,vc=(e,t)=>bc(e,t).join(" "),Sc=(e,t)=>bc(e,t).map(r=>oy(r)).join(" ");var ay=1e3*1e3*100,cy=({env:e,extendEnv:t,preferLocal:r,localDir:n,execPath:i})=>{let s=t?A(A({},Xt.default.env),e):e;return r?Ga({env:s,cwd:n,execPath:i}):s},uy=(e,t,r={})=>{let n=_c.default._parse(e,t,r);return e=n.command,t=n.args,r=n.options,r=A({maxBuffer:ay,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:r.cwd||Xt.default.cwd(),execPath:Xt.default.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0},r),r.env=cy(r),r.stdio=Xa(r),Xt.default.platform==="win32"&&wc.default.basename(e,".exe")==="cmd"&&t.unshift("/q"),{file:e,args:t,options:r,parsed:n}},hi=(e,t,r)=>typeof t!="string"&&!Ec.Buffer.isBuffer(t)?r===void 0?void 0:"":e.stripFinalNewline?Jn(t):t;function Ac(e,t,r){let n=uy(e,t,r),i=vc(e,t),s=Sc(e,t);oc(n.options);let o;try{o=mi.default.spawn(n.file,n.args,n.options)}catch(h){let p=new mi.default.ChildProcess,g=Promise.reject(ni({error:h,stdout:"",stderr:"",all:"",command:i,escapedCommand:s,parsed:n,timedOut:!1,isCanceled:!1,killed:!1}));return pi(p,g)}let a=yc(o),c=sc(o,n.options,a),l=ac(o,n.options,c),u={isCanceled:!1};o.kill=nc.bind(null,o.kill.bind(o)),o.cancel=ic.bind(null,o,u);let f=ja(async()=>{let[{error:h,exitCode:p,signal:g,timedOut:v},E,_,P]=await gc(o,n.options,l),D=hi(n.options,E),q=hi(n.options,_),M=hi(n.options,P);if(h||p!==0||g!==null){let O=ni({error:h,exitCode:p,signal:g,stdout:D,stderr:q,all:M,command:i,escapedCommand:s,parsed:n,timedOut:v,isCanceled:u.isCanceled||(n.options.signal?n.options.signal.aborted:!1),killed:o.killed});if(!n.options.reject)return O;throw O}return{command:i,escapedCommand:s,exitCode:0,stdout:D,stderr:q,all:M,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}});return hc(o,n.options.input),o.all=mc(o,n.options),pi(o,f)}var wi=Y(Cc());function Qt({result:e,index:t}){let[r,n]=e.subtitle[2].split(" - ");return _jsx(Me.List.Item,{key:e["@_uid"],title:(0,wi.decode)(e.title.toString()),subtitle:(0,wi.decode)(n),icon:e.icon,actions:_jsx(Me.ActionPanel,null,_jsx(Me.Action,{title:"Open in Dash",onAction:async()=>by(t)})),accessories:[{text:r}]})}async function by(e){await(0,Me.closeMainWindow)({clearRootSearch:!0}),await Ac("open",["-g","dash-workflow-callback://"+e])}var Bt=Y(require("node:fs"),1),Co=Y(require("node:path"),1),uh=Y(require("node:stream"),1),lh=require("node:util");var kc=require("util"),Or=Y(require("crypto"),1),Nc=(0,kc.promisify)(Or.default.randomBytes),vy="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~".split(""),Sy="0123456789".split(""),Ey="CDEHKMPRTUWXY012458".split(""),wy="!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".split(""),_y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),Ay=(e,t)=>{let r=t.length,n=Math.floor(65536/r)*r-1,i=2*Math.ceil(1.1*e),s="",o=0;for(;o<e;){let a=Or.default.randomBytes(i),c=0;for(;c<i&&o<e;){let l=a.readUInt16LE(c);c+=2,!(l>n)&&(s+=t[l%r],o++)}}return s},xy=async(e,t)=>{let r=t.length,n=Math.floor(65536/r)*r-1,i=2*Math.ceil(1.1*e),s="",o=0;for(;o<e;){let a=await Nc(i),c=0;for(;c<i&&o<e;){let l=a.readUInt16LE(c);c+=2,!(l>n)&&(s+=t[l%r],o++)}}return s},Ry=(e,t,r)=>Or.default.randomBytes(e).toString(t).slice(0,r),Ty=async(e,t,r)=>(await Nc(e)).toString(t).slice(0,r),qy=new Set([void 0,"hex","base64","url-safe","numeric","distinguishable","ascii-printable","alphanumeric"]),Lc=(e,t)=>({length:r,type:n,characters:i})=>{if(!(r>=0&&Number.isFinite(r)))throw new TypeError("Expected a `length` to be a non-negative finite number");if(n!==void 0&&i!==void 0)throw new TypeError("Expected either `type` or `characters`");if(i!==void 0&&typeof i!="string")throw new TypeError("Expected `characters` to be string");if(!qy.has(n))throw new TypeError(`Unknown type: ${n}`);if(n===void 0&&i===void 0&&(n="hex"),n==="hex"||n===void 0&&i===void 0)return t(Math.ceil(r*.5),"hex",r);if(n==="base64")return t(Math.ceil(r*.75),"base64",r);if(n==="url-safe")return e(r,vy);if(n==="numeric")return e(r,Sy);if(n==="distinguishable")return e(r,Ey);if(n==="ascii-printable")return e(r,wy);if(n==="alphanumeric")return e(r,_y);if(i.length===0)throw new TypeError("Expected `characters` string length to be greater than or equal to 1");if(i.length>65536)throw new TypeError("Expected `characters` string length to be less or equal to 65536");return e(r,i.split(""))},Ic=Lc(Ay,Ry);Ic.async=Lc(xy,Ty);var Dc=Ic;function _i(){return Dc({length:32})}var ko=Y(Mc(),1);function Bc(e){return e!==null&&typeof e=="object"&&typeof e.pipe=="function"}var fh=Y(ch(),1),I_=(0,lh.promisify)(uh.default.pipeline),dh=(e="")=>Co.default.join(ko.default,e+_i()),D_=async(e,t)=>I_(t,Bt.default.createWriteStream(e)),No=(e,{extraArguments:t=0}={})=>async(...r)=>{let[n,i]=r.slice(t),s=await e(...r.slice(0,t),i);try{return await n(s)}finally{await(0,fh.default)(s,{force:!0})}},le={};le.file=e=>{if(e=A({},e),e.name){if(e.extension!==void 0&&e.extension!==null)throw new Error("The `name` and `extension` options are mutually exclusive");return Co.default.join(le.directory(),e.name)}return dh()+(e.extension===void 0||e.extension===null?"":"."+e.extension.replace(/^\./,""))};le.file.task=No(le.file);le.directory=({prefix:e=""}={})=>{let t=dh(e);return Bt.default.mkdirSync(t),t};le.directory.task=No(le.directory);le.write=async(e,t)=>{let r=le.file(t);return await(Bc(e)?D_:Bt.promises.writeFile)(r,e),r};le.write.task=No(le.write,{extraArguments:1});le.writeSync=(e,t)=>{let r=le.file(t);return Bt.default.writeFileSync(r,e),r};Object.defineProperty(le,"root",{get(){return ko.default}});var ph=le;var Pn=require("react");var ix=Y(require("react"),1),sx=require("react");var nx=Y(tm(),1);var ox=require("@raycast/api");var jo=require("@raycast/api"),dt=require("react");function Ho(e,t){let[r,n]=(0,dt.useState)(!0),[i,s]=(0,dt.useState)(t);(0,dt.useEffect)(()=>{let a=!1;return(async()=>{let c=await jo.LocalStorage.getItem(e);typeof c=="string"&&(a||s(JSON.parse(c))),n(!1)})(),()=>{a=!0}},[]);let o=(0,dt.useCallback)(a=>{s(c=>{let l=typeof a=="function"?a(c):a;return jo.LocalStorage.setItem(e,JSON.stringify(l)),l})},[]);return[i,o,r]}var nm=require("child_process"),On=require("fs");var qn=require("react"),rm=require("@raycast/api");function pr(){let[e,t]=(0,qn.useState)(null);return(0,qn.useEffect)(()=>{(async()=>{let r=await(0,rm.getApplications)();for(let n of r)if(n.bundleId?.startsWith("com.kapeli.dash")){t(n);return}throw new Error("Dash.app not found")})()},[]),e}function Cn(){let[e,t]=(0,Pn.useState)(!0),[r,n,i]=Ho("docsets-v1",[]),s=pr();return(0,Pn.useEffect)(()=>{!s||(async()=>{t(!0);try{n(await cx(s))}catch{n([])}finally{t(!1)}})()},[s]),[r,e||i]}async function cx(e){let t=ph.file({extension:".json"});(0,nm.execSync)(`defaults read ${e.bundleId} docsets | plutil -convert json -r -o ${t} -`);let r=(0,On.readFileSync)(t,"utf8");return JSON.parse(r).map(n=>F(A({},n),{iconPath:ux(e.path,n.docsetPath,n.docsetBundle),docsetKeyword:lx(n.keyword||n.suggestedKeyword||n.pluginKeyword||n.docsetBundle)}))}function ux(e,t,r){return[`${t}/icon@2x.png`,`${t}/icon.png`,`${t}/icon.tiff`,`${e}/Contents/Resources/${r}.tiff`].find(On.existsSync)||"list-icon.png"}function lx(e){return e.substring(e.length-1)===":"?e.substring(0,e.length-1):e}var Ht=require("react"),Fm=Y(Dm()),Mm=require("child_process"),Bm=require("util");var Jx=(0,Bm.promisify)(Mm.execFile);function Ut(e,t=""){let[r,n]=(0,Ht.useState)({isLoading:!0,results:[]}),i=(0,Ht.useRef)(new AbortController),s=pr();return(0,Ht.useEffect)(()=>{if(!!s)return(async()=>{if(n(o=>F(A({},o),{isLoading:!0})),i.current?.abort(),i.current=new AbortController,!e){n({results:[],isLoading:!1});return}try{n({results:await eR(s,`${t?`${t}:`:""}${e}`,i.current.signal),isLoading:!1})}catch{n({results:[],isLoading:!1})}})(),function(){i.current?.abort()}},[s,e]),[r.results,r.isLoading]}async function eR(e,t,r){try{let{stdout:n}=await Jx("./dashAlfredWorkflow",[t],{cwd:`${e.path}/Contents/Resources`,signal:r}),i=(0,Fm.parse)(n,{ignoreAttributes:!1});return!i||typeof i.output>"u"?[]:Array.isArray(i.output.items.item)?i.output.items.item:[i.output.items.item]}catch(n){if(n instanceof Error&&n.name==="AbortError")return[];throw n}}var Gm=require("@raycast/api"),$m=require("react");function Mn({docset:e}){let[t,r]=(0,$m.useState)(""),[n,i]=Ut(t,e.docsetKeyword);return _jsx(Gm.List,{isLoading:i,searchBarPlaceholder:`Search in ${e.docsetName}`,onSearchTextChange:r,navigationTitle:`Search in ${e.docsetName}`},n.map((s,o)=>_jsx(Qt,{result:s,index:o,key:o})))}var tR=(e,t)=>e.filter(r=>r.docsetName.toLowerCase().includes(t.toLowerCase())||r.docsetKeyword.toLowerCase().includes(t.toLowerCase()));function Bn(e){let[t,r]=(0,jm.useState)(e.arguments.searchstring),[n,i]=Cn(),[s,o]=Ut(t),a=tR(n,t),c=n.map(l=>l.docsetKeyword);return _jsx(we.List,{isLoading:i||o,searchBarPlaceholder:"Filter docsets by name or keyword...",onSearchTextChange:l=>{let u=/(^\w+) /,d=u.test(l)&&l.match(u)?.[1],h=c.includes(d||"")?l.replace(u,"$1:"):l;r(h.trim())}},_jsx(we.List.Section,{title:"Docsets"},a.map(l=>_jsx(rR,{key:l.docsetPath,docset:l}))),_jsx(we.List.Section,{title:"Search Results"},s.map((l,u)=>_jsx(Qt,{result:l,index:u,key:u}))))}function rR({docset:e}){let{push:t}=(0,we.useNavigation)();return _jsx(we.List.Item,{title:e.docsetName,subtitle:e.docsetKeyword,icon:e.iconPath,actions:_jsx(we.ActionPanel,null,_jsx(we.Action,{title:"Open",onAction:()=>t(_jsx(Mn,{docset:e}))}))})}function Hm(e){return _jsx(Bn,{arguments:e.arguments})}module.exports=Jm(nR);0&&(module.exports={});
28: /*!
29:  * fill-range <https://github.com/jonschlinkert/fill-range>
30:  *
---

Raycast version

Version: 1.38.2

mattisssa commented 2 years ago

cc @sxn