1 line
3.9 KiB
JavaScript
1 line
3.9 KiB
JavaScript
import{d as $}from"./index-4bca499f.js";import{n as k}from"./application-default-icon-a19c8ba0.js";const v="/FlowOS/assets/softwarecenter-ac603202.svg",j={config:{name:"Store",type:"process",icon:v,targetVer:"1.0.0-indev.0"},run:async o=>{const u=await o.loadLibrary("lib/WindowManager").then(e=>e.createWindow({title:"Store",icon:v,width:500,height:700},o)),{fs:c}=o,n=await o.loadLibrary("lib/HTML"),{Button:g,Icon:s}=await o.loadLibrary("lib/Components");fetch(`${o.kernel.config.SERVER}/apps/list/`).then(async e=>await e.json()).then(E).catch(e=>console.error(e));async function m(){const a=await(await fetch(`${o.kernel.config.SERVER}/apps/list/`)).json(),y=new n(u.content).qs("div");a.forEach(async(r,x)=>{const p=y?.qsa("div")?.[x];p?.html(""),fetch(`${o.kernel.config.SERVER}/cors/?url=${r}`).then(async t=>await t.json()).then(t=>{t.apps.forEach(i=>{c.exists(`/home/Applications/${i.url.split("/").at(-1)?.replace(".js",".app")}`).then(d=>{const l=g.new().style({display:"flex",gap:"5px","align-items":"center"}).text("Uninstall").prepend(s.new("delete")).on("click",()=>f(i.url));d?fetch(`${o.kernel.config.SERVER}/cors?url=${i.url}`).then(async h=>await h.text()).then(async h=>{$.Buffer.from(await c.readFile(`/opt/apps/${i.url.split("/").at(-1)}`)).toString()!==h&&l.text("Update").prepend(s.new("update")).on("click",()=>w(i.url))}).catch(h=>console.error(h)):l.text("Install").prepend(s.new("download")).on("click",()=>w(i.url)),new n("div").style({display:"flex","flex-direction":"row",gap:"10px",padding:"10px",background:"var(--base)","border-radius":"10px"}).appendMany(new n("img").attr({src:i.icon??k}).style({"aspect-ratio":"1 / 1",width:"60px",height:"60px"}),new n("div").appendMany(new n("h3").style({margin:"0"}).text(i.name),l)).appendTo(p)}).catch(d=>console.error(d))})}).catch(t=>console.error(t))})}function E(e){u.content.innerHTML="";const a=new n("div").appendTo(u.content);e.forEach(y=>{fetch(`${o.kernel.config.SERVER}/cors/?url=${y}`).then(async r=>await r.json()).then(r=>{const x=s.new("arrow_drop_up");new n("h2").text(r.name).style({margin:"0",padding:"10px",display:"flex",gap:"5px","align-items":"center"}).prepend(x).appendTo(a).on("click",()=>{p.style({height:p.elm.style.height==="0px"?"max-content":"0"}),x.text(`arrow_drop_${p.elm.style.height==="0px"?"up":"down"}`)});const p=new n("div").appendTo(a).style({height:"0",display:"flex","flex-direction":"column",gap:"10px",overflow:"hidden",padding:"0 10px"});r.apps.forEach(t=>{c.exists(`/home/Applications/${t.url.split("/").at(-1)?.replace(".js",".app")}`).then(i=>{const d=g.new().style({display:"flex",gap:"5px","align-items":"center"}).text("Uninstall").prepend(s.new("delete")).on("click",()=>f(t.url));i?fetch(`${o.kernel.config.SERVER}/cors?url=${t.url}`).then(async l=>await l.text()).then(async l=>{$.Buffer.from(await c.readFile(`/opt/apps/${t.url.split("/").at(-1)}`)).toString()!==l&&d.text("Update").prepend(s.new("update")).un("click",()=>f(t.url)).on("click",()=>w(t.url))}).catch(l=>console.error(l)):d.text("Install").prepend(s.new("download")).un("click",()=>f(t.url)).on("click",()=>w(t.url)),new n("div").style({display:"flex","flex-direction":"row",gap:"10px",padding:"10px",background:"var(--base)","border-radius":"10px"}).appendMany(new n("img").attr({src:t.icon??k}).style({"aspect-ratio":"1 / 1",width:"60px",height:"60px"}),new n("div").appendMany(new n("h3").style({margin:"0"}).text(t.name),d)).appendTo(p)}).catch(i=>console.error(i))})}).catch(r=>console.error(r))})}function w(e){fetch(e).then(async a=>await a.text()).then(async a=>{await c.writeFile(`/home/Applications/${e.split("/").at(-1)?.replace(".js",".app")}`,`apps/${e.split("/").at(-1)?.split(".")[0]}`),await c.writeFile(`/opt/apps/${e.split("/").at(-1)}`,a),await m()}).catch(a=>console.error(a))}function f(e){c.unlink(`/home/Applications/${e.split("/").at(-1)?.replace(".js",".app")}`).then(async()=>{await c.unlink(`/opt/apps/${e.split("/").at(-1)}`),await m()}).catch(a=>console.error(a))}}};export{j as default};
|