const { app } = require('electron') const fs = require('fs') const path = require('path') // const unzipper = require('unzipper') const fse = require('fs-extra'); // function unzip(source, dest) { // return new Promise((resolve, reject) => { // fs.createReadStream(source) // .pipe(unzipper.Extract({ path: dest })) // .promise() // .then(() => resolve(true), (e) => reject(e)) // }); // } async function checkAppFolder(folderPath) { // check index.html const htmlFilePath = path.resolve(folderPath, './index.html') if (!await fs.existsSync(htmlFilePath)) { throw new Error('软件包中缺少入口index.html文件') } const htmlStr = await fs.readFileSync(htmlFilePath).toString() if (!htmlStr.includes(' { if (!(typeof json[k] === 'string' && json[k].length >= 2)) { throw new Error(`app.json里${k}字段不合法,必须是长度为2以上的字符串`) } }) return { ...json, logoFilePath, } } module.exports = async (event, zipPath) => { const tempDir = path.resolve(app.getPath('temp'), `./s207/install_apps/${Date.now()}`) // await unzip(zipPath, tempDir) const { id, name } = await checkAppFolder(tempDir) const targetDir = path.resolve(app.getPath('home'), `./s207/apps/${id}`) if (fse.pathExistsSync(targetDir)) { throw new Error(`【${name} id:${id}】应用已存在,请删除后重新安装`) } await fse.moveSync(tempDir, targetDir) return targetDir }