🐛 修复window运行

This commit is contained in:
刘嘉伟 2023-11-27 17:54:09 +08:00
parent 563374a4be
commit ac19bc8aca
4 changed files with 58 additions and 18 deletions

View File

@ -157,10 +157,18 @@ export const initFrpcApi = () => {
config.currentVersion,
(frpcVersionPath: string) => {
generateConfig(config, configPath => {
startFrpcProcess(
path.join(frpcVersionPath, "frpc"),
configPath
);
const platform = process.platform;
if (platform === 'win32') {
startFrpcProcess(
path.join(frpcVersionPath, "frpc.exe"),
configPath
);
}else {
startFrpcProcess(
path.join(frpcVersionPath, "frpc"),
configPath
);
}
});
}
);

View File

@ -5,6 +5,7 @@ const fs = require("fs");
const path = require("path");
const zlib = require("zlib");
const {download} = require("electron-dl");
const unzipper = require('unzipper');
const versionRelation = {
@ -12,12 +13,12 @@ const versionRelation = {
"win32_arm64": ["window", "arm64"],
"win32_ia32": ["window", "386"],
"darwin_arm64": ["darwin", "arm64"],
// "darwin_arm64": ["window", "amd64"],
"darwin_amd64": ["darwin", "amd64"],
}
const unTarGZ = tarGzPath => {
const unTarGZ = (tarGzPath: string, targetPath: string) => {
const tar = require("tar");
const targetPath = path.resolve(path.join(app.getPath("userData"), "frp"));
const unzip = zlib.createGunzip();
const readStream = fs.createReadStream(tarGzPath);
if (!fs.existsSync(unzip)) {
@ -34,6 +35,23 @@ const unTarGZ = tarGzPath => {
// console.log("解压完成!");
// });
};
const unZip = (zipPath: string, targetPath: string) => {
if (!fs.existsSync(path.join(targetPath, path.basename(zipPath, ".zip")))) {
fs.mkdirSync(path.join(targetPath, path.basename(zipPath, ".zip")), {recursive: true});
}
fs.createReadStream(zipPath)
.pipe(unzipper.ParseOne('frpc'))
.pipe(fs.createWriteStream(path.join(targetPath, path.basename(zipPath, ".zip"), "frpc.exe")))
.on('finish', () => {
console.log('File extracted successfully.');
})
.on('error', (err) => {
console.error('Error extracting file:', err);
});
return path.join("frp", path.basename(zipPath, ".zip"))
}
export const initGitHubApi = () => {
// 版本
let versions = [];
@ -114,12 +132,26 @@ export const initGitHubApi = () => {
});
},
onCompleted: () => {
const frpcVersionPath = unTarGZ(
path.join(
path.join(app.getPath("userData"), "download"),
`${asset.name}`
)
);
const targetPath = path.resolve(path.join(app.getPath("userData"), "frp"));
const ext = path.extname(asset.name)
let frpcVersionPath = ""
if (ext === '.zip') {
frpcVersionPath = unZip(path.join(
path.join(app.getPath("userData"), "download"),
`${asset.name}`
),
targetPath)
console.log(frpcVersionPath, '1')
} else if (ext === '.gz' && asset.name.includes(".tar.gz")) {
frpcVersionPath = unTarGZ(
path.join(
path.join(app.getPath("userData"), "download"),
`${asset.name}`
),
targetPath
);
}
version["frpcVersionPath"] = frpcVersionPath;
insertVersion(version, (err, document) => {
if (!err) {

View File

@ -49,14 +49,14 @@
"vite": "^4.4.9",
"vite-plugin-electron": "^0.15.3",
"vite-plugin-electron-renderer": "^0.14.5",
"vue-tsc": "^1.8.8",
"vue-types": "^5.1.1",
"electron-icon-builder": "^2.0.1",
"vue": "^3.3.4",
"vue-router": "^4.2.4"
"vue-router": "^4.2.4",
"vue-tsc": "^1.8.8",
"vue-types": "^5.1.1"
},
"dependencies": {
"electron-dl": "^3.5.1",
"tar": "^6.2.0"
"tar": "^6.2.0",
"unzipper": "^0.10.14"
}
}

View File

@ -96,7 +96,7 @@ onUnmounted(() => {
<div class="left">
<div class="mb-2">
<el-tag>{{ version.name }}</el-tag>
<el-tag class="ml-2">原文件名{{ version.assets[0]?.name }}</el-tag>
<!-- <el-tag class="ml-2">原文件名{{ version.assets[0]?.name }}</el-tag>-->
</div>
<div class="text-sm">
发布时间<span class="text-gray-00">{{