From ac19bc8acaf8d64dd740ad29beba89ebdba3d93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Mon, 27 Nov 2023 17:54:09 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8Dwindow=E8=BF=90?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api/frpc.ts | 16 +++++++++--- electron/api/github.ts | 48 ++++++++++++++++++++++++++++++------ package.json | 10 ++++---- src/views/download/index.vue | 2 +- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/electron/api/frpc.ts b/electron/api/frpc.ts index 95c547f..7dabac8 100644 --- a/electron/api/frpc.ts +++ b/electron/api/frpc.ts @@ -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 + ); + } }); } ); diff --git a/electron/api/github.ts b/electron/api/github.ts index 2fe8308..383c986 100644 --- a/electron/api/github.ts +++ b/electron/api/github.ts @@ -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) { diff --git a/package.json b/package.json index 71d4896..c72b1e4 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/views/download/index.vue b/src/views/download/index.vue index c0f8d8b..d0a072d 100644 --- a/src/views/download/index.vue +++ b/src/views/download/index.vue @@ -96,7 +96,7 @@ onUnmounted(() => {