const iData=require("./initData"),launcherUtil=require("./launcherUtil");let serverDir;iData.then(e=>{serverDir=e.serverDir});const PieServer=require("pieServer"),path=require("path"),pfs=require("pfs"),util=require("util");let copydir=require("copy-dir");copydir=util.promisify(copydir);let{app:app,ipcMain:ipcMain,BrowserWindow:BrowserWindow}=require("electron");module.exports={async open({appName:e,dirpath:r}){let t=path.normalize(`${r}/page.json`);try{await pfs.stat(t)}catch(e){return{stat:0,error:"no page.json"}}let a=new BrowserWindow({show:!1,webPreferences:{nodeIntegration:!0}});return a.loadURL(`file://${__dirname}/server/server.html?data=${encodeURIComponent(JSON.stringify({appName:e,dirpath:r}))}`),a.on("close",e=>{a=null}),{stat:1}},async create({appName:e,dirpath:r}){let t=`${serverDir}/${e}/new/default`;try{await copydir(path.normalize(t),r);let e=await pfs.readFile(r+"/page.json");e=JSON.parse(e);let a=path.basename(r);e.name=a,pfs.writeFile(r+"/page.json",JSON.stringify(e))}catch(e){return{stat:!1,error:e.toString()}}return{stat:1}}};