feat: Support Both Stable and Alpha Version (#47)

This commit is contained in:
WhizPanda 2023-12-03 14:26:03 +08:00 committed by GitHub
parent b10c1d5006
commit 2b646636c1
7 changed files with 99 additions and 182 deletions

View File

@ -5,7 +5,7 @@ on:
push: push:
tags: tags:
- v** - v**
permissions: write-all
env: env:
CARGO_INCREMENTAL: 0 CARGO_INCREMENTAL: 0
RUST_BACKTRACE: short RUST_BACKTRACE: short

View File

@ -1,7 +1,7 @@
name: Updater CI name: Updater CI
on: workflow_dispatch on: workflow_dispatch
permissions: write-all
jobs: jobs:
release-update: release-update:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -11,47 +11,6 @@ const cwd = process.cwd();
const TEMP_DIR = path.join(cwd, "node_modules/.verge"); const TEMP_DIR = path.join(cwd, "node_modules/.verge");
const FORCE = process.argv.includes("--force"); const FORCE = process.argv.includes("--force");
/* ======= clash =======
const CLASH_STORAGE_PREFIX = "https://release.dreamacro.workers.dev/";
const CLASH_URL_PREFIX =
"https://github.com/Dreamacro/clash/releases/download/premium/";
const CLASH_LATEST_DATE = "latest";
const CLASH_BACKUP_URL_PREFIX =
"https://github.com/zhongfly/Clash-premium-backup/releases/download/";
const CLASH_BACKUP_LATEST_DATE = "2023-09-05-gdcc8d87";
//https://github.com/zhongfly/Clash-premium-backup/releases/download/2023-09-05-gdcc8d87/clash-windows-amd64-2023-09-05-gdcc8d87.zip
//https://github.com/zhongfly/Clash-premium-backup/releases/download/2023-09-05-gdcc8d87/clash-windows-amd64-n2023-09-05-gdcc8d87.zip
const CLASH_MAP = {
"win32-x64": "clash-windows-amd64",
"darwin-x64": "clash-darwin-amd64",
"darwin-arm64": "clash-darwin-arm64",
"linux-x64": "clash-linux-amd64",
"linux-arm64": "clash-linux-arm64",
};
*/
/* ======= clash meta ======= */
const VERSION_URL =
"https://github.com/MetaCubeX/mihomo/releases/download/v1.17.0/version.txt";
const META_URL_PREFIX = `https://github.com/MetaCubeX/mihomo/releases/download/v1.17.0`;
let META_VERSION;
const META_MAP = {
"win32-x64": "mihomo-windows-amd64",
"win32-ia32": "mihomo-windows-386",
"win32-arm64": "mihomo-windows-arm64",
"darwin-x64": "mihomo-darwin-amd64",
"darwin-arm64": "mihomo-darwin-arm64",
"linux-x64": "mihomo-linux-amd64",
"linux-arm64": "mihomo-linux-arm64",
"linux-arm": "mihomo-linux-armv7",
};
/*
* check available
*/
const PLATFORM_MAP = { const PLATFORM_MAP = {
"x86_64-pc-windows-msvc": "win32", "x86_64-pc-windows-msvc": "win32",
"i686-pc-windows-msvc": "win32", "i686-pc-windows-msvc": "win32",
@ -73,22 +32,9 @@ const ARCH_MAP = {
"armv7-unknown-linux-gnueabihf": "arm", "armv7-unknown-linux-gnueabihf": "arm",
}; };
/** const arg1 = process.argv.slice(2)[0];
* Fetch the latest release version from the version.txt file const arg2 = process.argv.slice(2)[1];
*/ const target = arg1 === "--force" ? arg2 : arg1;
async function getLatestVersion() {
try {
const response = await fetch(VERSION_URL, { method: "GET" });
let v = await response.text();
META_VERSION = v.trim(); // Trim to remove extra whitespaces
console.log(`Latest release version: ${META_VERSION}`);
} catch (error) {
console.error("Error fetching latest release version:", error.message);
process.exit(1);
}
}
const target = process.argv.slice(2)[0];
const { platform, arch } = target const { platform, arch } = target
? { platform: PLATFORM_MAP[target], arch: ARCH_MAP[target] } ? { platform: PLATFORM_MAP[target], arch: ARCH_MAP[target] }
: process; : process;
@ -98,74 +44,92 @@ const SIDECAR_HOST = target
: execSync("rustc -vV") : execSync("rustc -vV")
.toString() .toString()
.match(/(?<=host: ).+(?=\s*)/g)[0]; .match(/(?<=host: ).+(?=\s*)/g)[0];
/*
if (!CLASH_MAP[`${platform}-${arch}`]) { /* ======= clash meta alpha======= */
throw new Error(`clash unsupported platform "${platform}-${arch}"`); const VERSION_URL =
"https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha/version.txt";
const META_ALPHA_URL_PREFIX = `https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha`;
let META_ALPHA_VERSION;
const META_ALPHA_MAP = {
"win32-x64": "mihomo-windows-amd64",
"win32-ia32": "mihomo-windows-386",
"win32-arm64": "mihomo-windows-arm64",
"darwin-x64": "mihomo-darwin-amd64",
"darwin-arm64": "mihomo-darwin-arm64",
"linux-x64": "mihomo-linux-amd64",
"linux-arm64": "mihomo-linux-arm64",
"linux-arm": "mihomo-linux-armv7",
};
// Fetch the latest release version from the version.txt file
async function getLatestVersion() {
try {
const response = await fetch(VERSION_URL, { method: "GET" });
let v = await response.text();
META_ALPHA_VERSION = v.trim(); // Trim to remove extra whitespaces
console.log(`Latest release version: ${META_ALPHA_VERSION}`);
} catch (error) {
console.error("Error fetching latest release version:", error.message);
process.exit(1);
}
} }
*/
/* ======= clash meta stable ======= */
const META_URL_PREFIX = `https://github.com/MetaCubeX/mihomo/releases/download`;
let META_VERSION = "v1.17.0";
const META_MAP = {
"win32-x64": "mihomo-windows-amd64",
"win32-ia32": "mihomo-windows-386",
"win32-arm64": "mihomo-windows-arm64",
"darwin-x64": "mihomo-darwin-amd64",
"darwin-arm64": "mihomo-darwin-arm64",
"linux-x64": "mihomo-linux-amd64",
"linux-arm64": "mihomo-linux-arm64",
"linux-arm": "mihomo-linux-armv7",
};
/*
* check available
*/
if (!META_MAP[`${platform}-${arch}`]) { if (!META_MAP[`${platform}-${arch}`]) {
throw new Error(`clash meta unsupported platform "${platform}-${arch}"`); throw new Error(
`clash meta alpha unsupported platform "${platform}-${arch}"`
);
} }
/*
function clash() {
const name = CLASH_MAP[`${platform}-${arch}`];
if (!META_ALPHA_MAP[`${platform}-${arch}`]) {
throw new Error(
`clash meta alpha unsupported platform "${platform}-${arch}"`
);
}
/**
* core info
*/
function clashMetaAlpha() {
const name = META_ALPHA_MAP[`${platform}-${arch}`];
const isWin = platform === "win32"; const isWin = platform === "win32";
const urlExt = isWin ? "zip" : "gz"; const urlExt = isWin ? "zip" : "gz";
const downloadURL = `${CLASH_URL_PREFIX}${name}-${CLASH_LATEST_DATE}.${urlExt}`; const downloadURL = `${META_ALPHA_URL_PREFIX}/${name}-${META_ALPHA_VERSION}.${urlExt}`;
const exeFile = `${name}${isWin ? ".exe" : ""}`; const exeFile = `${name}${isWin ? ".exe" : ""}`;
const zipFile = `${name}.${urlExt}`; const zipFile = `${name}-${META_ALPHA_VERSION}.${urlExt}`;
return { return {
name: "clash", name: "clash-meta-alpha",
targetFile: `clash-${SIDECAR_HOST}${isWin ? ".exe" : ""}`, targetFile: `clash-meta-alpha-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
exeFile, exeFile,
zipFile, zipFile,
downloadURL, downloadURL,
}; };
} }
function clashBackup() {
const name = CLASH_MAP[`${platform}-${arch}`];
const isWin = platform === "win32";
const urlExt = isWin ? "zip" : "gz";
const downloadURL = `${CLASH_BACKUP_URL_PREFIX}${CLASH_BACKUP_LATEST_DATE}/${name}-n${CLASH_BACKUP_LATEST_DATE}.${urlExt}`;
const exeFile = `${name}${isWin ? ".exe" : ""}`;
const zipFile = `${name}.${urlExt}`;
return {
name: "clash",
targetFile: `clash-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
exeFile,
zipFile,
downloadURL,
};
}
function clashS3() {
const name = CLASH_MAP[`${platform}-${arch}`];
const isWin = platform === "win32";
const urlExt = isWin ? "zip" : "gz";
const downloadURL = `${CLASH_STORAGE_PREFIX}${CLASH_LATEST_DATE}/${name}-${CLASH_LATEST_DATE}.${urlExt}`;
const exeFile = `${name}${isWin ? ".exe" : ""}`;
const zipFile = `${name}.${urlExt}`;
return {
name: "clash",
targetFile: `clash-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
exeFile,
zipFile,
downloadURL,
};
}
*/
function clashMeta() { function clashMeta() {
const name = META_MAP[`${platform}-${arch}`]; const name = META_MAP[`${platform}-${arch}`];
const isWin = platform === "win32"; const isWin = platform === "win32";
const urlExt = isWin ? "zip" : "gz"; const urlExt = isWin ? "zip" : "gz";
const downloadURL = `${META_URL_PREFIX}/${name}-${META_VERSION}.${urlExt}`; const downloadURL = `${META_URL_PREFIX}/${META_VERSION}/${name}-${META_VERSION}.${urlExt}`;
const exeFile = `${name}${isWin ? ".exe" : ""}`; const exeFile = `${name}${isWin ? ".exe" : ""}`;
const zipFile = `${name}-${META_VERSION}.${urlExt}`; const zipFile = `${name}-${META_VERSION}.${urlExt}`;
@ -177,7 +141,6 @@ function clashMeta() {
downloadURL, downloadURL,
}; };
} }
/** /**
* download sidecar and rename * download sidecar and rename
*/ */
@ -259,58 +222,6 @@ async function resolveSidecar(binInfo) {
} }
} }
/**
* prepare clash core
* if the core version is not updated in time, use S3 storage as a backup.
*/
async function resolveClash() {
try {
return await resolveSidecar(clash());
} catch {
console.log(`[WARN]: clash core needs to be updated`);
return await resolveSidecar(clashS3());
}
}
/**
* only Windows
* get the wintun.dll (not required)
async function resolveWintun() {
const { platform } = process;
if (platform !== "win32") return;
const url = "https://www.wintun.net/builds/wintun-0.14.1.zip";
const tempDir = path.join(TEMP_DIR, "wintun");
const tempZip = path.join(tempDir, "wintun.zip");
const wintunPath = path.join(tempDir, "wintun/bin/amd64/wintun.dll");
const targetPath = path.join(cwd, "src-tauri/resources", "wintun.dll");
if (!FORCE && (await fs.pathExists(targetPath))) return;
await fs.mkdirp(tempDir);
if (!(await fs.pathExists(tempZip))) {
await downloadFile(url, tempZip);
}
// unzip
const zip = new AdmZip(tempZip);
zip.extractAllTo(tempDir, true);
if (!(await fs.pathExists(wintunPath))) {
throw new Error(`path not found "${wintunPath}"`);
}
await fs.rename(wintunPath, targetPath);
await fs.remove(tempDir);
console.log(`[INFO]: resolve wintun.dll finished`);
}
*/
/** /**
* download the file to the resources dir * download the file to the resources dir
*/ */
@ -399,9 +310,14 @@ const resolveEnableLoopback = () =>
const tasks = [ const tasks = [
// { name: "clash", func: resolveClash, retry: 5 }, // { name: "clash", func: resolveClash, retry: 5 },
{
name: "clash-meta-alpha",
func: () => getLatestVersion().then(() => resolveSidecar(clashMetaAlpha())),
retry: 5,
},
{ {
name: "clash-meta", name: "clash-meta",
func: () => getLatestVersion().then(() => resolveSidecar(clashMeta())), func: () => resolveSidecar(clashMeta()),
retry: 5, retry: 5,
}, },
// { name: "wintun", func: resolveWintun, retry: 5, winOnly: true }, // { name: "wintun", func: resolveWintun, retry: 5, winOnly: true },

View File

@ -147,6 +147,7 @@ impl CoreManager {
// fix #212 // fix #212
let args = match clash_core.as_str() { let args = match clash_core.as_str() {
"clash-meta" => vec!["-m", "-d", app_dir, "-f", config_path], "clash-meta" => vec!["-m", "-d", app_dir, "-f", config_path],
"clash-meta-alpha" => vec!["-m", "-d", app_dir, "-f", config_path],
_ => vec!["-d", app_dir, "-f", config_path], _ => vec!["-d", app_dir, "-f", config_path],
}; };
@ -258,8 +259,9 @@ impl CoreManager {
/// 切换核心 /// 切换核心
pub async fn change_core(&self, clash_core: Option<String>) -> Result<()> { pub async fn change_core(&self, clash_core: Option<String>) -> Result<()> {
let clash_core = clash_core.ok_or(anyhow::anyhow!("clash core is null"))?; let clash_core = clash_core.ok_or(anyhow::anyhow!("clash core is null"))?;
const CLASH_CORES: [&str; 3] = ["clash", "clash-meta", "clash-meta-alpha"];
if &clash_core != "clash" && &clash_core != "clash-meta" { if !CLASH_CORES.contains(&clash_core.as_str()) {
bail!("invalid clash core name \"{clash_core}\""); bail!("invalid clash core name \"{clash_core}\"");
} }

View File

@ -21,6 +21,7 @@ pub enum ChainType {
pub enum ChainSupport { pub enum ChainSupport {
Clash, Clash,
ClashMeta, ClashMeta,
ClashMetaAlpha,
All, All,
} }
@ -60,9 +61,19 @@ impl ChainItem {
let hy_alpn = let hy_alpn =
ChainItem::to_script("verge_hy_alpn", include_str!("./builtin/meta_hy_alpn.js")); ChainItem::to_script("verge_hy_alpn", include_str!("./builtin/meta_hy_alpn.js"));
// meta 的一些处理
let meta_guard_alpha =
ChainItem::to_script("verge_meta_guard", include_str!("./builtin/meta_guard.js"));
// meta 1.13.2 alpn string 转 数组
let hy_alpn_alpha =
ChainItem::to_script("verge_hy_alpn", include_str!("./builtin/meta_hy_alpn.js"));
vec![ vec![
(ChainSupport::ClashMeta, hy_alpn), (ChainSupport::ClashMeta, hy_alpn),
(ChainSupport::ClashMeta, meta_guard), (ChainSupport::ClashMeta, meta_guard),
(ChainSupport::ClashMetaAlpha, hy_alpn_alpha),
(ChainSupport::ClashMetaAlpha, meta_guard_alpha),
] ]
} }
@ -81,6 +92,7 @@ impl ChainSupport {
(ChainSupport::All, _) => true, (ChainSupport::All, _) => true,
(ChainSupport::Clash, "clash") => true, (ChainSupport::Clash, "clash") => true,
(ChainSupport::ClashMeta, "clash-meta") => true, (ChainSupport::ClashMeta, "clash-meta") => true,
(ChainSupport::ClashMetaAlpha, "clash-meta-alpha") => true,
_ => false, _ => false,
}, },
None => true, None => true,

View File

@ -26,7 +26,7 @@
"icons/icon.ico" "icons/icon.ico"
], ],
"resources": ["resources"], "resources": ["resources"],
"externalBin": ["sidecar/clash-meta"], "externalBin": ["sidecar/clash-meta", "sidecar/clash-meta-alpha"],
"copyright": "© 2022 zzzgydi All Rights Reserved", "copyright": "© 2022 zzzgydi All Rights Reserved",
"category": "DeveloperTool", "category": "DeveloperTool",
"shortDescription": "A Clash GUI based on tauri.", "shortDescription": "A Clash GUI based on tauri.",

View File

@ -18,11 +18,10 @@ import { closeAllConnections } from "@/services/api";
import { grantPermission } from "@/services/cmds"; import { grantPermission } from "@/services/cmds";
import getSystem from "@/utils/get-system"; import getSystem from "@/utils/get-system";
/* const VALID_CORE = [ const VALID_CORE = [
{ name: "Clash", core: "clash" },
{ name: "Clash Meta", core: "clash-meta" }, { name: "Clash Meta", core: "clash-meta" },
]; */ { name: "Clash Meta Alpha", core: "clash-meta-alpha" },
const VALID_CORE = [{ name: "Clash Meta", core: "clash-meta" }]; ];
const OS = getSystem(); const OS = getSystem();
@ -38,7 +37,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
close: () => setOpen(false), close: () => setOpen(false),
})); }));
const { clash_core = "clash" } = verge ?? {}; const { clash_core = "clash-meta" } = verge ?? {};
const onCoreChange = useLockFn(async (core: string) => { const onCoreChange = useLockFn(async (core: string) => {
if (core === clash_core) return; if (core === clash_core) return;
@ -92,7 +91,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
contentSx={{ contentSx={{
pb: 0, pb: 0,
width: 320, width: 320,
height: 90, height: 180,
overflowY: "auto", overflowY: "auto",
userSelect: "text", userSelect: "text",
marginTop: "-8px", marginTop: "-8px",
@ -112,18 +111,6 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
<ListItemText primary={each.name} secondary={`/${each.core}`} /> <ListItemText primary={each.name} secondary={`/${each.core}`} />
{(OS === "macos" || OS === "linux") && ( {(OS === "macos" || OS === "linux") && (
/* <IconButton
color="inherit"
size="small"
edge="end"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onGrant(each.core);
}}
>
<Lock fontSize="inherit" />
</IconButton> */
<Tooltip title={t("Tun mode requires")}> <Tooltip title={t("Tun mode requires")}>
<Button <Button
variant="outlined" variant="outlined"