import{c as a,a as w,i as y,b as n}from"./createLucideIcon-mjjtyxlm.js";import{S as g,N as B}from"./Navbar-e42_J4ze.js";import{P as v,a as b,_ as F}from"./Checkbox-_zq52Lmd.js";import{a as p}from"./fetch_utils-9iXjNOiI.js";import{T as k,S,C}from"./trash-2-YONst-Qs.js";import{S as P}from"./save-DWz7vErV.js";import{R as x}from"./rotate-ccw-DTIrC0O4.js";import{F as T}from"./file-text-DLPhJfqV.js";import"./Notification-E6BjStlk.js";/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const M=a("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const E=a("folder-open",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const j=a("folder-up",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}],["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"m9 13 3-3 3 3",key:"1pxg3c"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=a("folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const A=a("hard-drive",[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const N=a("layers-plus",[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 .83.18 2 2 0 0 0 .83-.18l8.58-3.9a1 1 0 0 0 0-1.831z",key:"zzgyd3"}],["path",{d:"M16 17h6",key:"1ook5g"}],["path",{d:"M19 14v6",key:"1ckrd5"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 .825.178",key:"1ia9y3"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l2.116-.962",key:"jksky3"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _=a("square-pen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const O=a("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $=a("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),z=w({components:{Navbar:B,Checkbox:F,ArrowRight:M,Check:C,Edit:_,FileText:T,Folder:L,FolderOpen:E,FolderUp:j,HardDrive:A,LayersPlus:N,Play:b,Plus:v,RotateCcw:x,Save:P,Search:S,Shield:g,Terminal:O,Trash2:k,X:$},data(){return{apps:[],showEditForm:!1,editForm:null,detachedCmd:"",coverSearching:!1,coverFinderBusy:!1,coverCandidates:[],coverSearchQuery:"",platform:"",fileBrowserType:"any",fileBrowserTitle:"",fileBrowserCallback:null,fileBrowserCurrentPath:"",fileBrowserParentPath:"",fileBrowserEntries:[],fileBrowserLoading:!1,fileBrowserError:"",fileBrowserSelectedPath:"",fileBrowserTypedPath:""}},created(){fetch("./api/apps").then(e=>e.json()).then(e=>{console.log(e),this.apps=e.apps}),fetch("./api/config").then(e=>e.json()).then(e=>this.platform=e.platform)},methods:{newApp(){this.editForm={name:"",output:"",cmd:"",index:-1,"exclude-global-prep-cmd":!1,elevated:!1,"auto-detach":!0,"wait-all":!0,"exit-timeout":5,"prep-cmd":[],detached:[],"image-path":""},this.editForm.index=-1,this.showEditForm=!0},editApp(e){this.editForm=JSON.parse(JSON.stringify(this.apps[e])),this.editForm.index=e,this.editForm["prep-cmd"]===void 0&&(this.editForm["prep-cmd"]=[]),this.editForm.detached===void 0&&(this.editForm.detached=[]),this.editForm["exclude-global-prep-cmd"]===void 0&&(this.editForm["exclude-global-prep-cmd"]=!1),this.editForm.elevated===void 0&&this.platform==="windows"&&(this.editForm.elevated=!1),this.editForm["auto-detach"]===void 0&&(this.editForm["auto-detach"]=!0),this.editForm["wait-all"]===void 0&&(this.editForm["wait-all"]=!0),this.editForm["exit-timeout"]===void 0&&(this.editForm["exit-timeout"]=5),this.showEditForm=!0},showDeleteForm(e){confirm("Are you sure to delete "+this.apps[e].name+"?")&&p("./api/apps/"+e,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(t=>{t.status===200&&document.location.reload()})},addPrepCmd(){let e={do:"",undo:""};this.platform==="windows"&&(e={...e,elevated:!1}),this.editForm["prep-cmd"].push(e)},deletePrepCmd(e){this.editForm["prep-cmd"].splice(e,1)},addDetached(){this.editForm.detached.push("")},showCoverFinder(){this.coverCandidates=[],this.coverSearchQuery="",this.performCoverSearch()},performCoverSearch(){this.coverSearching=!0,this.coverCandidates=[];const e=this.coverSearchQuery.trim()||this.editForm.name.toString();function r(i){let h=i.substring(0,Math.min(i.length,2)).toLowerCase().replaceAll(/[^a-z\d]/g,"");return h||"@"}function t(i){if(!i)return Promise.resolve([]);let h=i.replaceAll(/\s+/g,".").toLowerCase(),c="https://raw.githubusercontent.com/LizardByte/GameDB/gh-pages",u=r(i);return fetch(`${c}/buckets/${u}.json`).then(function(o){if(!o.ok)throw new Error("Failed to search covers");return o.json()}).then(o=>Promise.all(Object.keys(o).map(s=>o[s].name.replaceAll(/\s+/g,".").toLowerCase().startsWith(h)?fetch(`${c}/games/${s}.json`).then(function(d){return d.json()}).catch(()=>null):null).filter(s=>s))).then(o=>o.filter(s=>s&&s.cover&&s.cover.url).map(s=>{const l=s.cover.url,d=l.lastIndexOf("."),f=l.lastIndexOf("/");if(d<0||f<0)return null;const m=l.substring(f+1,d);return{name:s.name,key:`igdb_${s.id}`,url:`https://images.igdb.com/igdb/image/upload/t_cover_big/${m}.jpg`,saveUrl:`https://images.igdb.com/igdb/image/upload/t_cover_big_2x/${m}.png`}}).filter(s=>s))}t(e).then(i=>this.coverCandidates=i).finally(()=>this.coverSearching=!1)},useCover(e){this.coverFinderBusy=!0,p("./api/covers/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,url:e.saveUrl})}).then(r=>{if(!r.ok)throw new Error("Failed to download covers");return r.json()}).then(r=>{this.editForm["image-path"]=r.path;const t=this.$refs.coverFinderModal;if(t){const i=n.Modal.getInstance(t);i&&i.hide()}}).finally(()=>this.coverFinderBusy=!1)},browseFor(e,r,t,i){this.fileBrowserType=e,this.fileBrowserTitle=this.$t(r),this.fileBrowserCallback=i,this.fileBrowserSelectedPath=t||"",this.fileBrowserTypedPath=t||"",this.fileBrowserError="",this.fileBrowserNavigate(t||""),n.Modal.getOrCreateInstance(this.$refs.fileBrowserModal).show()},fileBrowserClose(){const e=n.Modal.getInstance(this.$refs.fileBrowserModal);e&&e.hide()},fileBrowserConfirm(){const e=this.fileBrowserSelectedPath||this.fileBrowserTypedPath;e&&(this.fileBrowserCallback&&(this.fileBrowserCallback(e),this.fileBrowserCallback=null),this.fileBrowserClose())},fileBrowserNavigate(e){this.fileBrowserLoading=!0,this.fileBrowserError="";const r=new URLSearchParams({type:this.fileBrowserType});e&&r.set("path",e),fetch(`./api/browse?${r.toString()}`).then(t=>t.ok?t.json():t.json().then(i=>{throw new Error(i.error||"Browse failed")})).then(t=>{this.fileBrowserCurrentPath=t.path??"",this.fileBrowserParentPath=t.parent??"",this.fileBrowserEntries=t.entries??[],this.fileBrowserTypedPath=t.path??"",this.fileBrowserSelectedPath=this.fileBrowserType==="directory"?t.path??"":""}).catch(t=>{this.fileBrowserError=t.message}).finally(()=>{this.fileBrowserLoading=!1})},fileBrowserNavigateUp(){this.fileBrowserNavigate(this.fileBrowserParentPath)},fileBrowserSelectEntry(e){e.type==="directory"?this.fileBrowserNavigate(e.path):(this.fileBrowserSelectedPath=e.path,this.fileBrowserTypedPath=e.path)},fileBrowserActivateEntry(e){e.type==="directory"?this.fileBrowserNavigate(e.path):(this.fileBrowserSelectedPath=e.path,this.fileBrowserTypedPath=e.path,this.fileBrowserConfirm())},fileBrowserOnTypedInput(){this.fileBrowserSelectedPath=this.fileBrowserTypedPath},browsePrep(e,r){const t=this.editForm["prep-cmd"][e][r]||"";this.browseFor("executable","file_browser.select_executable",t,i=>{this.editForm["prep-cmd"][e][r]=i})},browseDetached(e){const r=this.editForm.detached[e]||"";this.browseFor("executable","file_browser.select_executable",r,t=>{this.editForm.detached[e]=t})},save(){this.editForm["image-path"]=this.editForm["image-path"].toString().replace(/"/g,""),p("./api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(this.editForm)}).then(e=>{e.status===200&&document.location.reload()})},handleImageError(e){e.target.style.display="none";const r=e.target.nextElementSibling;r&&r.classList.contains("app-poster-placeholder")&&(r.style.display="flex")}}});y(z);
