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.83 kB
JavaScript
/*! 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 j=Object.create;var{getPrototypeOf:P,defineProperty:Q,getOwnPropertyNames:$,getOwnPropertyDescriptor:T}=Object,f=Object.prototype.hasOwnProperty;var W=(q,z,D)=>{D=q!=null?j(P(q)):{};let F=z||!q||!q.__esModule?Q(D,"default",{value:q,enumerable:!0}):D;for(let L of $(q))if(!f.call(F,L))Q(F,L,{get:()=>q[L],enumerable:!0});return F},_=new WeakMap,h=(q)=>{var z=_.get(q),D;if(z)return z;if(z=Q({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function")$(q).map((F)=>!f.call(z,F)&&Q(z,F,{get:()=>q[F],enumerable:!(D=T(q,F))||D.enumerable}));return _.set(q,z),z};var k=(q,z)=>{for(var D in z)Q(q,D,{get:z[D],enumerable:!0,configurable:!0,set:(F)=>z[D]=()=>F})};var y={};k(y,{shutdown:()=>I,sendEvent:()=>x,run:()=>C,ready:()=>g,disableBunCheck:()=>p,default:()=>c,broadcast:()=>E});module.exports=h(y);var S,X,m=async(q)=>{try{let z=await(0,eval)(q.detail.js);S.send(JSON.stringify({token:X,command:"execResult",id:q.detail.requestId,returnValue:z}))}catch(z){S.send(JSON.stringify({token:X,command:"execResult",id:q.detail.requestId,error:z.message,stack:z.stack}))}},A=async(q,z,D)=>{S=D,X=z,q.events.on("buntralinoEval",m),q.events.on("buntralinoNavigate",(F)=>{window.location.href=F.detail.url}),q.events.on("buntralinoReload",()=>{window.location.reload()})};var v=()=>Date.now().toString(36)+Math.random().toString(36),G;if(window.Neutralino)G=window.Neutralino;var M,Y,K,B,H,U=new Promise((q,z)=>{B=q,H=z}),V=!0,p=()=>{V=!1};(async()=>{if(!G)G=(await import("@neutralinojs/lib")).default;G.events.on("ready",async()=>{if(V&&window.NL_RESMODE==="bundle"&&!window.NL_ARGS.some((q)=>q.startsWith("--buntralino-name="))){let q=await G.app.getConfig(),z=`${window.NL_CWD}/${q.cli.binaryName}`;if(window.NL_OS==="Windows")z+=".exe";try{G.filesystem.getStats(z),await G.os.execCommand(`"${z}"`,{background:!0,cwd:window.NL_CWD}),G.app.exit()}catch(D){window.alert('"neutralino" is not the main executable! Please run the other one.'),G.app.exit()}finally{return}}try{let q=window.NL_ARGS.find((J)=>J.startsWith("--buntralino-port=")),z=window.NL_ARGS.find((J)=>J.startsWith("--buntralino-name="));if(!q||!z)return;let[,D]=q.split("="),[,F]=z.split("="),L=window.NL_TOKEN||sessionStorage.NL_TOKEN;K=new WebSocket(`ws://127.0.0.1:${D}`),K.onopen=()=>{console.debug("⚛️ Announcing ourself to Buntralino…"),K.send(JSON.stringify({command:"announceSelf",name:F,NL_PORT:window.NL_PORT,NL_TOKEN:L}))};let O=(J)=>{if(G.events.off("buntralinoRegisterParent",O),!J.detail.token||!J.detail.port)return;M=J.detail.token,Y=J.detail.port,K=new WebSocket(`ws://127.0.0.1:${Y}`),K.onopen=()=>{A(G,M,K),console.log("⚛️\uD83E\uDD5F Buntralino connected on port",Y),B()}};G.events.on("buntralinoRegisterParent",O)}catch(q){H(q),console.error("⚛️ Buntralino failed with",q)}}),G.init()})();var C=async(q,z)=>{await U;let D=v();return K.send(JSON.stringify({token:M,command:"run",method:q,id:D,payload:z})),new Promise((F,L)=>{let O=(J)=>{let{id:w,returnValue:N,error:R,stack:Z}=J.detail;if(w===D){if(G.events.off("buntralinoExecResult",O),"error"in J.detail)L(new Error(R??"Unknown error",{cause:Z?new Error(Z):null}));F(N)}};G.events.on("buntralinoExecResult",O)})},I=()=>{K.send(JSON.stringify({token:M,command:"shutdown"}))},E=(q,z)=>{K.send(JSON.stringify({token:M,command:"broadcast",event:q,payload:z}))},x=(q,z,D)=>{K.send(JSON.stringify({token:M,command:"sendEvent",event:z,target:q,payload:D}))},g=U,c={run:C,ready:g,shutdown:I,broadcast:E,sendEvent:x};
//# debugId=C9C39C9CFA6E8B7864756E2164756E21
//# sourceMappingURL=index.cjs.map