UNPKG

buntralino-client

Version:

Neutralino.js library for Buntralino. Buntralino unites Bun and Neutralino.js to make a simpler, lighter alternative to Electron and NW.js. Use Neutralino.js API at client and send harder tasks to Bun while keeping your development process easy.

6 lines (4 loc) 3.72 kB
/*! Buntralino client. Buntralino unites Bun and Neutralino.js to make a simpler, lighter alternative to Electron and NW.js. Use Neutralino.js API at client and send harder tasks to Bun while keeping your development process easy. © Cosmo Myzrail Gorynych 2024, MIT License. */ var C=Object.create;var{getPrototypeOf:I,defineProperty:Z,getOwnPropertyNames:E}=Object;var x=Object.prototype.hasOwnProperty;var g=(q,z,D)=>{D=q!=null?C(I(q)):{};let K=z||!q||!q.__esModule?Z(D,"default",{value:q,enumerable:!0}):D;for(let L of E(q))if(!x.call(K,L))Z(K,L,{get:()=>q[L],enumerable:!0});return K};var w=((q)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(q,{get:(z,D)=>(typeof require!=="undefined"?require:z)[D]}):q)(function(q){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+q+'" is not supported')});var Q,S,N=async(q)=>{try{let z=await(0,eval)(q.detail.js);Q.send(JSON.stringify({token:S,command:"execResult",id:q.detail.requestId,returnValue:z}))}catch(z){Q.send(JSON.stringify({token:S,command:"execResult",id:q.detail.requestId,error:z.message,stack:z.stack}))}},_=async(q,z,D)=>{Q=D,S=z,q.events.on("buntralinoEval",N),q.events.on("buntralinoNavigate",(K)=>{window.location.href=K.detail.url}),q.events.on("buntralinoReload",()=>{window.location.reload()})};var R=()=>Date.now().toString(36)+Math.random().toString(36),F;if(window.Neutralino)F=window.Neutralino;var M,X,J,$,f,A=new Promise((q,z)=>{$=q,f=z}),B=!0,p=()=>{B=!1};(async()=>{if(!F)F=(await import("@neutralinojs/lib")).default;F.events.on("ready",async()=>{if(B&&window.NL_RESMODE==="bundle"&&!window.NL_ARGS.some((q)=>q.startsWith("--buntralino-name="))){let q=await F.app.getConfig(),z=`${window.NL_CWD}/${q.cli.binaryName}`;if(window.NL_OS==="Windows")z+=".exe";try{F.filesystem.getStats(z),await F.os.execCommand(`"${z}"`,{background:!0,cwd:window.NL_CWD}),F.app.exit()}catch(D){window.alert('"neutralino" is not the main executable! Please run the other one.'),F.app.exit()}finally{return}}try{let q=window.NL_ARGS.find((G)=>G.startsWith("--buntralino-port=")),z=window.NL_ARGS.find((G)=>G.startsWith("--buntralino-name="));if(!q||!z)return;let[,D]=q.split("="),[,K]=z.split("="),L=window.NL_TOKEN||sessionStorage.NL_TOKEN;J=new WebSocket(`ws://127.0.0.1:${D}`),J.onopen=()=>{console.debug("⚛️ Announcing ourself to Buntralino…"),J.send(JSON.stringify({command:"announceSelf",name:K,NL_PORT:window.NL_PORT,NL_TOKEN:L}))};let O=(G)=>{if(F.events.off("buntralinoRegisterParent",O),!G.detail.token||!G.detail.port)return;M=G.detail.token,X=G.detail.port,J=new WebSocket(`ws://127.0.0.1:${X}`),J.onopen=()=>{_(F,M,J),console.log("⚛️\uD83E\uDD5F Buntralino connected on port",X),$()}};F.events.on("buntralinoRegisterParent",O)}catch(q){f(q),console.error("⚛️ Buntralino failed with",q)}}),F.init()})();var j=async(q,z)=>{await A;let D=R();return J.send(JSON.stringify({token:M,command:"run",method:q,id:D,payload:z})),new Promise((K,L)=>{let O=(G)=>{let{id:H,returnValue:U,error:V,stack:Y}=G.detail;if(H===D){if(F.events.off("buntralinoExecResult",O),"error"in G.detail)L(new Error(V??"Unknown error",{cause:Y?new Error(Y):null}));K(U)}};F.events.on("buntralinoExecResult",O)})},P=()=>{J.send(JSON.stringify({token:M,command:"shutdown"}))},T=(q,z)=>{J.send(JSON.stringify({token:M,command:"broadcast",event:q,payload:z}))},W=(q,z,D)=>{J.send(JSON.stringify({token:M,command:"sendEvent",event:z,target:q,payload:D}))},h=A,c={run:j,ready:h,shutdown:P,broadcast:T,sendEvent:W};export{P as shutdown,W as sendEvent,j as run,h as ready,p as disableBunCheck,c as default,T as broadcast}; //# debugId=2A5E97728ECE554464756E2164756E21 //# sourceMappingURL=index.mjs.map