Browse Source

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

WhizPanda 1 year ago
parent
commit
fc90094e8a

+ 1 - 1
.github/workflows/release.yml

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

+ 1 - 1
.github/workflows/updater.yml

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

+ 72 - 156
scripts/check.mjs

@@ -11,47 +11,6 @@ const cwd = process.cwd();
 const TEMP_DIR = path.join(cwd, "node_modules/.verge");
 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 = {
   "x86_64-pc-windows-msvc": "win32",
   "i686-pc-windows-msvc": "win32",
@@ -73,22 +32,9 @@ const ARCH_MAP = {
   "armv7-unknown-linux-gnueabihf": "arm",
 };
 
-/**
- * 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_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 arg1 = process.argv.slice(2)[0];
+const arg2 = process.argv.slice(2)[1];
+const target = arg1 === "--force" ? arg2 : arg1;
 const { platform, arch } = target
   ? { platform: PLATFORM_MAP[target], arch: ARCH_MAP[target] }
   : process;
@@ -98,74 +44,92 @@ const SIDECAR_HOST = target
   : execSync("rustc -vV")
       .toString()
       .match(/(?<=host: ).+(?=\s*)/g)[0];
-/*
-if (!CLASH_MAP[`${platform}-${arch}`]) {
-  throw new Error(`clash unsupported platform "${platform}-${arch}"`);
-}
-*/
-if (!META_MAP[`${platform}-${arch}`]) {
-  throw new Error(`clash meta unsupported platform "${platform}-${arch}"`);
-}
-/*
-function clash() {
-  const name = CLASH_MAP[`${platform}-${arch}`];
 
-  const isWin = platform === "win32";
-  const urlExt = isWin ? "zip" : "gz";
-  const downloadURL = `${CLASH_URL_PREFIX}${name}-${CLASH_LATEST_DATE}.${urlExt}`;
-  const exeFile = `${name}${isWin ? ".exe" : ""}`;
-  const zipFile = `${name}.${urlExt}`;
+/* ======= clash meta alpha======= */
+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;
 
-  return {
-    name: "clash",
-    targetFile: `clash-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
-    exeFile,
-    zipFile,
-    downloadURL,
-  };
+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);
+  }
 }
 
-function clashBackup() {
-  const name = CLASH_MAP[`${platform}-${arch}`];
+/* ======= clash meta stable ======= */
+const META_URL_PREFIX = `https://github.com/MetaCubeX/mihomo/releases/download`;
+let META_VERSION = "v1.17.0";
 
-  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}`;
+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",
+};
 
-  return {
-    name: "clash",
-    targetFile: `clash-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
-    exeFile,
-    zipFile,
-    downloadURL,
-  };
+/*
+ * check available
+ */
+if (!META_MAP[`${platform}-${arch}`]) {
+  throw new Error(
+    `clash meta alpha unsupported platform "${platform}-${arch}"`
+  );
 }
 
-function clashS3() {
-  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 urlExt = isWin ? "zip" : "gz";
-  const downloadURL = `${CLASH_STORAGE_PREFIX}${CLASH_LATEST_DATE}/${name}-${CLASH_LATEST_DATE}.${urlExt}`;
+  const downloadURL = `${META_ALPHA_URL_PREFIX}/${name}-${META_ALPHA_VERSION}.${urlExt}`;
   const exeFile = `${name}${isWin ? ".exe" : ""}`;
-  const zipFile = `${name}.${urlExt}`;
+  const zipFile = `${name}-${META_ALPHA_VERSION}.${urlExt}`;
 
   return {
-    name: "clash",
-    targetFile: `clash-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
+    name: "clash-meta-alpha",
+    targetFile: `clash-meta-alpha-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
     exeFile,
     zipFile,
     downloadURL,
   };
 }
-*/
+
 function clashMeta() {
   const name = META_MAP[`${platform}-${arch}`];
   const isWin = platform === "win32";
   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 zipFile = `${name}-${META_VERSION}.${urlExt}`;
 
@@ -177,7 +141,6 @@ function clashMeta() {
     downloadURL,
   };
 }
-
 /**
  * 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
  */
@@ -399,9 +310,14 @@ const resolveEnableLoopback = () =>
 
 const tasks = [
   // { name: "clash", func: resolveClash, retry: 5 },
+  {
+    name: "clash-meta-alpha",
+    func: () => getLatestVersion().then(() => resolveSidecar(clashMetaAlpha())),
+    retry: 5,
+  },
   {
     name: "clash-meta",
-    func: () => getLatestVersion().then(() => resolveSidecar(clashMeta())),
+    func: () => resolveSidecar(clashMeta()),
     retry: 5,
   },
   // { name: "wintun", func: resolveWintun, retry: 5, winOnly: true },

+ 3 - 1
src-tauri/src/core/core.rs

@@ -147,6 +147,7 @@ impl CoreManager {
         // fix #212
         let args = match clash_core.as_str() {
             "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],
         };
 
@@ -258,8 +259,9 @@ impl CoreManager {
     /// 切换核心
     pub async fn change_core(&self, clash_core: Option<String>) -> Result<()> {
         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}\"");
         }
 

+ 12 - 0
src-tauri/src/enhance/chain.rs

@@ -21,6 +21,7 @@ pub enum ChainType {
 pub enum ChainSupport {
     Clash,
     ClashMeta,
+    ClashMetaAlpha,
     All,
 }
 
@@ -60,9 +61,19 @@ impl ChainItem {
         let hy_alpn =
             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![
             (ChainSupport::ClashMeta, hy_alpn),
             (ChainSupport::ClashMeta, meta_guard),
+            (ChainSupport::ClashMetaAlpha, hy_alpn_alpha),
+            (ChainSupport::ClashMetaAlpha, meta_guard_alpha),
         ]
     }
 
@@ -81,6 +92,7 @@ impl ChainSupport {
                 (ChainSupport::All, _) => true,
                 (ChainSupport::Clash, "clash") => true,
                 (ChainSupport::ClashMeta, "clash-meta") => true,
+                (ChainSupport::ClashMetaAlpha, "clash-meta-alpha") => true,
                 _ => false,
             },
             None => true,

+ 1 - 1
src-tauri/tauri.conf.json

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

+ 5 - 18
src/components/setting/mods/clash-core-viewer.tsx

@@ -18,11 +18,10 @@ import { closeAllConnections } from "@/services/api";
 import { grantPermission } from "@/services/cmds";
 import getSystem from "@/utils/get-system";
 
-/* const VALID_CORE = [
-  { name: "Clash", core: "clash" },
+const VALID_CORE = [
   { name: "Clash Meta", core: "clash-meta" },
-]; */
-const VALID_CORE = [{ name: "Clash Meta", core: "clash-meta" }];
+  { name: "Clash Meta Alpha", core: "clash-meta-alpha" },
+];
 
 const OS = getSystem();
 
@@ -38,7 +37,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
     close: () => setOpen(false),
   }));
 
-  const { clash_core = "clash" } = verge ?? {};
+  const { clash_core = "clash-meta" } = verge ?? {};
 
   const onCoreChange = useLockFn(async (core: string) => {
     if (core === clash_core) return;
@@ -92,7 +91,7 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
       contentSx={{
         pb: 0,
         width: 320,
-        height: 90,
+        height: 180,
         overflowY: "auto",
         userSelect: "text",
         marginTop: "-8px",
@@ -112,18 +111,6 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
             <ListItemText primary={each.name} secondary={`/${each.core}`} />
 
             {(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")}>
                 <Button
                   variant="outlined"