pucoti/www/public/neutralino.js
Félix Dorn c3ee96429c init
2025-06-19 12:27:59 +02:00

1 line
16 KiB
JavaScript

var Neutralino=function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function n(e,t){return window.addEventListener(e,t),Promise.resolve({success:!0,message:"Event listener added"})}function r(e,t){const n=new CustomEvent(e,{detail:t});return window.dispatchEvent(n),Promise.resolve({success:!0,message:"Message dispatched"})}function i(e){const t=window.atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return r.buffer}function o(e){let t=new Uint8Array(e),n="";for(let e of t)n+=String.fromCharCode(e);return window.btoa(n)}let s;"function"==typeof SuppressedError&&SuppressedError;const a={},c=[],u={};function d(){window.NL_TOKEN&&sessionStorage.setItem("NL_TOKEN",window.NL_TOKEN);const e=p().split(".")[1],o=window.NL_GINJECTED||window.NL_CINJECTED?"127.0.0.1":window.location.hostname;s=new WebSocket(`ws://${o}:${window.NL_PORT}?connectToken=${e}`),function(){if(n("ready",(()=>t(this,void 0,void 0,(function*(){if(yield f(c),!window.NL_EXTENABLED)return;let e=yield l("extensions.getStats");for(let t of e.connected)r("extensionReady",t)})))),n("extClientConnect",(e=>{r("extensionReady",e.detail)})),!window.NL_EXTENABLED)return;n("extensionReady",(e=>t(this,void 0,void 0,(function*(){e.detail in u&&(yield f(u[e.detail]),delete u[e.detail])}))))}(),function(){s.addEventListener("message",(e=>{var t,n,o;const c=JSON.parse(e.data);c.id&&c.id in a?((null===(t=c.data)||void 0===t?void 0:t.error)?(a[c.id].reject(c.data.error),"NE_RT_INVTOKN"==c.data.error.code&&(s.close(),document.body.innerText="",document.write("<code>NE_RT_INVTOKN</code>: Neutralinojs application cannot execute native methods since <code>NL_TOKEN</code> is invalid."))):(null===(n=c.data)||void 0===n?void 0:n.success)&&a[c.id].resolve(c.data.hasOwnProperty("returnValue")?c.data.returnValue:c.data),delete a[c.id]):c.event&&("openedFile"==c.event&&"dataBinary"==(null===(o=null==c?void 0:c.data)||void 0===o?void 0:o.action)&&(c.data.data=i(c.data.data)),r(c.event,c.data))})),s.addEventListener("open",(e=>t(this,void 0,void 0,(function*(){r("ready")})))),s.addEventListener("close",(e=>t(this,void 0,void 0,(function*(){r("serverOffline",{code:"NE_CL_NSEROFF",message:"Neutralino server is offline. Try restarting the application"})})))),s.addEventListener("error",(e=>t(this,void 0,void 0,(function*(){document.body.innerText="",document.write("<code>NE_CL_IVCTOKN</code>: Neutralinojs application cannot connect with the framework core using <code>NL_TOKEN</code>.")}))))}()}function l(e,t){return new Promise(((n,r)=>{if((null==s?void 0:s.readyState)!=WebSocket.OPEN)return i={method:e,data:t,resolve:n,reject:r},void c.push(i);var i;const o="10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))),u=p();a[o]={resolve:n,reject:r},s.send(JSON.stringify({id:o,method:e,data:t,accessToken:u}))}))}function f(e){return t(this,void 0,void 0,(function*(){for(;e.length>0;){const t=e.shift();try{const e=yield l(t.method,t.data);t.resolve(e)}catch(e){t.reject(e)}}}))}function p(){return window.NL_TOKEN||sessionStorage.getItem("NL_TOKEN")||""}function g(e,t){return l("filesystem.writeBinaryFile",{path:e,data:o(t)})}var w={__proto__:null,appendBinaryFile:function(e,t){return l("filesystem.appendBinaryFile",{path:e,data:o(t)})},appendFile:function(e,t){return l("filesystem.appendFile",{path:e,data:t})},copy:function(e,t,n){return l("filesystem.copy",Object.assign({source:e,destination:t},n))},createDirectory:function(e){return l("filesystem.createDirectory",{path:e})},createWatcher:function(e){return l("filesystem.createWatcher",{path:e})},getAbsolutePath:function(e){return l("filesystem.getAbsolutePath",{path:e})},getOpenedFileInfo:function(e){return l("filesystem.getOpenedFileInfo",{id:e})},getPathParts:function(e){return l("filesystem.getPathParts",{path:e})},getPermissions:function(e){return l("filesystem.getPermissions",{path:e})},getRelativePath:function(e,t){return l("filesystem.getRelativePath",{path:e,base:t})},getStats:function(e){return l("filesystem.getStats",{path:e})},getWatchers:function(){return l("filesystem.getWatchers")},move:function(e,t){return l("filesystem.move",{source:e,destination:t})},openFile:function(e){return l("filesystem.openFile",{path:e})},readBinaryFile:function(e,t){return new Promise(((n,r)=>{l("filesystem.readBinaryFile",Object.assign({path:e},t)).then((e=>{n(i(e))})).catch((e=>{r(e)}))}))},readDirectory:function(e,t){return l("filesystem.readDirectory",Object.assign({path:e},t))},readFile:function(e,t){return l("filesystem.readFile",Object.assign({path:e},t))},remove:function(e){return l("filesystem.remove",{path:e})},removeWatcher:function(e){return l("filesystem.removeWatcher",{id:e})},setPermissions:function(e,t,n){return l("filesystem.setPermissions",Object.assign(Object.assign({path:e},t),{mode:n}))},updateOpenedFile:function(e,t,n){return l("filesystem.updateOpenedFile",{id:e,event:t,data:n})},writeBinaryFile:g,writeFile:function(e,t){return l("filesystem.writeFile",{path:e,data:t})}};function m(e,t){return l("os.execCommand",Object.assign({command:e},t))}var h={__proto__:null,execCommand:m,getEnv:function(e){return l("os.getEnv",{key:e})},getEnvs:function(){return l("os.getEnvs")},getPath:function(e){return l("os.getPath",{name:e})},getSpawnedProcesses:function(){return l("os.getSpawnedProcesses")},open:function(e){return l("os.open",{url:e})},setTray:function(e){return l("os.setTray",e)},showFolderDialog:function(e,t){return l("os.showFolderDialog",Object.assign({title:e},t))},showMessageBox:function(e,t,n,r){return l("os.showMessageBox",{title:e,content:t,choice:n,icon:r})},showNotification:function(e,t,n){return l("os.showNotification",{title:e,content:t,icon:n})},showOpenDialog:function(e,t){return l("os.showOpenDialog",Object.assign({title:e},t))},showSaveDialog:function(e,t){return l("os.showSaveDialog",Object.assign({title:e},t))},spawnProcess:function(e,t){return l("os.spawnProcess",Object.assign({command:e},t))},updateSpawnedProcess:function(e,t,n){return l("os.updateSpawnedProcess",{id:e,event:t,data:n})}};var v={__proto__:null,getArch:function(){return l("computer.getArch")},getCPUInfo:function(){return l("computer.getCPUInfo")},getDisplays:function(){return l("computer.getDisplays")},getKernelInfo:function(){return l("computer.getKernelInfo")},getMemoryInfo:function(){return l("computer.getMemoryInfo")},getMousePosition:function(){return l("computer.getMousePosition")},getOSInfo:function(){return l("computer.getOSInfo")}};var y={__proto__:null,getData:function(e){return l("storage.getData",{key:e})},getKeys:function(){return l("storage.getKeys")},setData:function(e,t){return l("storage.setData",{key:e,data:t})}};function _(e,t){return l("debug.log",{message:e,type:t})}var b={__proto__:null,log:_};function E(e){return l("app.exit",{code:e})}var N={__proto__:null,broadcast:function(e,t){return l("app.broadcast",{event:e,data:t})},exit:E,getConfig:function(){return l("app.getConfig")},killProcess:function(){return l("app.killProcess")},readProcessInput:function(e){return l("app.readProcessInput",{readAll:e})},restartProcess:function(e){return new Promise((n=>t(this,void 0,void 0,(function*(){let t=window.NL_ARGS.reduce(((e,t)=>(t.includes(" ")&&(t=`"${t}"`),e+=" "+t)),"");(null==e?void 0:e.args)&&(t+=" "+e.args),yield m(t,{background:!0}),E(),n()}))))},writeProcessError:function(e){return l("app.writeProcessError",{data:e})},writeProcessOutput:function(e){return l("app.writeProcessOutput",{data:e})}};const P=new WeakMap;function O(e,t){return l("window.move",{x:e,y:t})}function T(){return l("window.getSize")}var L={__proto__:null,center:function(){return l("window.center")},create:function(e,t){return new Promise(((n,r)=>{function i(e){return"string"!=typeof e||(e=e.trim()).includes(" ")&&(e=`"${e}"`),e}t=Object.assign(Object.assign({},t),{useSavedState:!1});let o=window.NL_ARGS.reduce(((e,t,n)=>((t.includes("--path=")||t.includes("--debug-mode")||t.includes("--load-dir-res")||0==n)&&(e+=" "+i(t)),e)),"");o+=" --url="+i(e);for(let e in t){if("processArgs"==e)continue;o+=` --window${"-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}=${i(t[e])}`}t&&t.processArgs&&(o+=" "+t.processArgs),m(o,{background:!0}).then((e=>{n(e)})).catch((e=>{r(e)}))}))},exitFullScreen:function(){return l("window.exitFullScreen")},focus:function(){return l("window.focus")},getPosition:function(){return l("window.getPosition")},getSize:T,getTitle:function(){return l("window.getTitle")},hide:function(){return l("window.hide")},isFullScreen:function(){return l("window.isFullScreen")},isMaximized:function(){return l("window.isMaximized")},isMinimized:function(){return l("window.isMinimized")},isVisible:function(){return l("window.isVisible")},maximize:function(){return l("window.maximize")},minimize:function(){return l("window.minimize")},move:O,setAlwaysOnTop:function(e){return l("window.setAlwaysOnTop",{onTop:e})},setDraggableRegion:function(e,n={}){return new Promise(((r,i)=>{const o=e instanceof Element?e:document.getElementById(e);let s=0,a=0,c=0,u=!1,d=performance.now(),l=n.alwaysCapture;if(!o)return i({code:"NE_WD_DOMNOTF",message:"Unable to find DOM element"});if(P.has(o))return i({code:"NE_WD_ALRDREL",message:"This DOM element is already an active draggable region"});function f(e){return t(this,void 0,void 0,(function*(){var t;const r=e.clientX-s,i=e.clientY-a;if(c=Math.sqrt(r*r+i*i),c>=(null!==(t=n.dragMinDistance)&&void 0!==t?t:10)&&(u=!0,l||(o.setPointerCapture(e.pointerId),l=!0)),u){const t=performance.now(),n=t-d;if(n<5)return;return d=t-(n-5),void(yield O(e.screenX-s,e.screenY-a))}}))}function p(e){0===e.button&&(s=e.clientX,a=e.clientY,o.addEventListener("pointermove",f),n.alwaysCapture&&o.setPointerCapture(e.pointerId))}function g(e){o.removeEventListener("pointermove",f),o.releasePointerCapture(e.pointerId)}o.addEventListener("pointerdown",p),o.addEventListener("pointerup",g),o.addEventListener("pointercancel",g),P.set(o,{pointerdown:p,pointerup:g}),r({success:!0,message:"Draggable region was activated"})}))},setFullScreen:function(){return l("window.setFullScreen")},setIcon:function(e){return l("window.setIcon",{icon:e})},setMainMenu:function(e){return l("window.setMainMenu",e)},setSize:function(e){return new Promise(((n,r)=>t(this,void 0,void 0,(function*(){let t=yield T();l("window.setSize",e=Object.assign(Object.assign({},t),e)).then((e=>{n(e)})).catch((e=>{r(e)}))}))))},setTitle:function(e){return l("window.setTitle",{title:e})},show:function(){return l("window.show")},snapshot:function(e){return l("window.snapshot",{path:e})},unmaximize:function(){return l("window.unmaximize")},unminimize:function(){return l("window.unminimize")},unsetDraggableRegion:function(e){return new Promise(((t,n)=>{const r=e instanceof Element?e:document.getElementById(e);if(!r)return n({code:"NE_WD_DOMNOTF",message:"Unable to find DOM element"});if(!P.has(r))return n({code:"NE_WD_NOTDRRE",message:"DOM element is not an active draggable region"});const{pointerdown:i,pointerup:o}=P.get(r);r.removeEventListener("pointerdown",i),r.removeEventListener("pointerup",o),r.removeEventListener("pointercancel",o),P.delete(r),t({success:!0,message:"Draggable region was deactivated"})}))}};var S={__proto__:null,broadcast:function(e,t){return l("events.broadcast",{event:e,data:t})},dispatch:r,off:function(e,t){return window.removeEventListener(e,t),Promise.resolve({success:!0,message:"Event listener removed"})},on:n};function D(){return l("extensions.getStats")}var x={__proto__:null,broadcast:function(e,t){return l("extensions.broadcast",{event:e,data:t})},dispatch:function(e,n,r){return new Promise(((i,o)=>t(this,void 0,void 0,(function*(){const t=yield D();if(t.loaded.includes(e))if(t.connected.includes(e))try{const t=yield l("extensions.dispatch",{extensionId:e,event:n,data:r});i(t)}catch(e){o(e)}else!function(e,t){e in u?u[e].push(t):u[e]=[t]}(e,{method:"extensions.dispatch",data:{extensionId:e,event:n,data:r},resolve:i,reject:o});else o({code:"NE_EX_EXTNOTL",message:`${e} is not loaded`})}))))},getStats:D};let F=null;var M={__proto__:null,checkForUpdates:function(e){return new Promise(((n,r)=>t(this,void 0,void 0,(function*(){if(!e)return r({code:"NE_RT_NATRTER",message:"Missing require parameter: url"});try{const t=yield fetch(e);F=JSON.parse(yield t.text()),!function(e){return!!(e.applicationId&&e.applicationId==window.NL_APPID&&e.version&&e.resourcesURL)}(F)?r({code:"NE_UP_CUPDMER",message:"Invalid update manifest or mismatching applicationId"}):n(F)}catch(e){r({code:"NE_UP_CUPDERR",message:"Unable to fetch update manifest"})}}))))},install:function(){return new Promise(((e,n)=>t(this,void 0,void 0,(function*(){if(!F)return n({code:"NE_UP_UPDNOUF",message:"No update manifest loaded"});try{const t=yield fetch(F.resourcesURL),n=yield t.arrayBuffer();yield g(window.NL_PATH+"/resources.neu",n),e({success:!0,message:"Update installed. Restart the process to see updates"})}catch(e){n({code:"NE_UP_UPDINER",message:"Update installation error"})}}))))}};var C={__proto__:null,clear:function(){return l("clipboard.clear")},getFormat:function(){return l("clipboard.getFormat")},readHTML:function(){return l("clipboard.readHTML")},readImage:function(e=""){return new Promise(((t,n)=>{l("clipboard.readImage").then((n=>{if(n){const r=window.atob(n.data);let i,o,s,a=32==n.bpp?4:3;switch(e.toLowerCase()){case"rgb":i=n.width*n.height*3,o=[0,1,2];break;case"rgba":i=n.width*n.height*4,o=[0,1,2,3];break;case"argb":i=n.width*n.height*4,o=[3,0,1,2];break;case"bgra":i=n.width*n.height*4,o=[2,1,0,3];break;default:i=r.length,s=new Uint8Array(i);for(let e=0;e<i;e++)s[e]=r.charCodeAt(e);return n.data=s,void t(n)}s=new Uint8Array(i);let c,u,d,l,f,p=255==new Uint8Array(new Uint32Array([255]).buffer)[0],g=[],w=0;for(let e=0;e<r.length;e+=a)c=r.charCodeAt(e),u=r.charCodeAt(e+1),d=r.charCodeAt(e+2),l=4==a?r.charCodeAt(e+3):255,f=p?(l<<24|d<<16|u<<8|c)>>>0:(c<<24|u<<16|d<<8|l)>>>0,g=[f>>n.redShift&255,f>>n.greenShift&255,f>>n.blueShift&255,f>>n.alphaShift&255],o.forEach(((e,t)=>{s[t+w]=g[e]})),w+=o.length;n.data=s}t(n)})).catch((e=>{n(e)}))}))},readText:function(){return l("clipboard.readText")},writeHTML:function(e){return l("clipboard.writeHTML",{data:e})},writeImage:function(e){const t=Object.assign({},e);return(null==e?void 0:e.data)&&(t.data=o(e.data)),l("clipboard.writeImage",t)},writeText:function(e){return l("clipboard.writeText",{data:e})}};var I={__proto__:null,extractDirectory:function(e,t){return l("resources.extractDirectory",{path:e,destination:t})},extractFile:function(e,t){return l("resources.extractFile",{path:e,destination:t})},getFiles:function(){return l("resources.getFiles")},getStats:function(e){return l("resources.getStats",{path:e})},readBinaryFile:function(e){return new Promise(((t,n)=>{l("resources.readBinaryFile",{path:e}).then((e=>{t(i(e))})).catch((e=>{n(e)}))}))},readFile:function(e){return l("resources.readFile",{path:e})}};var A={__proto__:null,getMounts:function(){return l("server.getMounts")},mount:function(e,t){return l("server.mount",{path:e,target:t})},unmount:function(e){return l("server.unmount",{path:e})}};var R={__proto__:null,getMethods:function(){return l("custom.getMethods")}};let j=!1;return e.app=N,e.clipboard=C,e.computer=v,e.custom=R,e.debug=b,e.events=S,e.extensions=x,e.filesystem=w,e.init=function(e={}){if(e=Object.assign({exportCustomMethods:!0},e),!j){if(d(),window.NL_ARGS.find((e=>"--neu-dev-auto-reload"==e))&&n("neuDev_reloadApp",(()=>t(this,void 0,void 0,(function*(){yield _("Reloading the application..."),location.reload()})))),e.exportCustomMethods&&window.NL_CMETHODS&&window.NL_CMETHODS.length>0)for(const e of window.NL_CMETHODS)Neutralino.custom[e]=(...t)=>{let n={};for(const[e,r]of t.entries())n="object"!=typeof r||Array.isArray(r)||null==r?Object.assign(Object.assign({},n),{["arg"+e]:r}):Object.assign(Object.assign({},n),r);return l("custom."+e,n)};window.NL_CVERSION="6.1.0",window.NL_CCOMMIT="425c526c318342e0e5d0f17caceef2a53049eda4",j=!0}},e.os=h,e.resources=I,e.server=A,e.storage=y,e.updater=M,e.window=L,e}({});