🐛 版本过滤

This commit is contained in:
刘嘉伟 2023-11-27 17:03:45 +08:00
parent eef54cfccc
commit 7c10ad1341
2 changed files with 122 additions and 106 deletions

View File

@ -1,10 +1,19 @@
import { app, BrowserWindow, ipcMain, net } from "electron";
import { insertVersion } from "../storage/version";
import {app, BrowserWindow, ipcMain, net} from "electron";
import {insertVersion} from "../storage/version";
const fs = require("fs");
const path = require("path");
const zlib = require("zlib");
const { download } = require("electron-dl");
const {download} = require("electron-dl");
const versionRelation = {
"win32_x64": ["window", "amd64"],
"win32_arm64": ["window", "arm64"],
"win32_ia32": ["window", "386"],
"darwin_arm64": ["darwin", "arm64"],
"darwin_amd64": ["darwin", "amd64"],
}
const unTarGZ = tarGzPath => {
const tar = require("tar");
@ -12,7 +21,7 @@ const unTarGZ = tarGzPath => {
const unzip = zlib.createGunzip();
const readStream = fs.createReadStream(tarGzPath);
if (!fs.existsSync(unzip)) {
fs.mkdirSync(targetPath, { recursive: true });
fs.mkdirSync(targetPath, {recursive: true});
}
readStream.pipe(unzip).pipe(
tar.extract({
@ -34,13 +43,22 @@ export const initGitHubApi = () => {
};
const getAdaptiveAsset = versionId => {
const version = getVersion(versionId);
const {assets} = getVersion(versionId);
const arch = process.arch;
const platform = process.platform;
const { assets } = version;
const asset = assets.find(
f => f.name.indexOf(platform) != -1 && f.name.indexOf(arch) != -1
f => {
const a = versionRelation[`${platform}_${arch}`]
if (a) {
const flag = a.every(item => f.name.includes(item))
return flag;
}
return false;
}
);
if (asset) {
console.log(asset.name)
}
return asset;
};
@ -67,15 +85,9 @@ export const initGitHubApi = () => {
.map(m => {
const asset = getAdaptiveAsset(m.id);
if (asset) {
// const absPath = `${downloadPath}/${asset.id}_${asset.name}`;
const absPath = `${downloadPath}/${asset.name}`;
m.download_completed = fs.existsSync(absPath);
} else {
console.log("buzhicih");
}
// m.download_completed = fs.existsSync(
// `${downloadPath}/${asset.id}_${asset.name}`
// );
return m;
});
event.reply("Download.frpVersionHook", returnVersionsData);
@ -90,7 +102,7 @@ export const initGitHubApi = () => {
ipcMain.on("github.download", async (event, args) => {
const version = getVersion(args);
const asset = getAdaptiveAsset(args);
const { browser_download_url } = asset;
const {browser_download_url} = asset;
// 数据目录
await download(BrowserWindow.getFocusedWindow(), browser_download_url, {
filename: `${asset.name}`,

View File

@ -129,6 +129,10 @@ ipcMain.handle("open-win", (_, arg) => {
}
});
ipcMain.on('open-url', (event, url) => {
shell.openExternal(url).then(r => {});
});
initGitHubApi();
initConfigApi();
initProxyApi();