2021-12-24 01:58:15 +08:00
|
|
|
import fs from "fs-extra";
|
2021-12-29 01:01:09 +08:00
|
|
|
import zlib from "zlib";
|
2023-11-28 07:49:44 +08:00
|
|
|
import tar from "tar";
|
2021-12-24 01:58:15 +08:00
|
|
|
import path from "path";
|
|
|
|
import AdmZip from "adm-zip";
|
|
|
|
import fetch from "node-fetch";
|
2022-04-17 00:37:21 +08:00
|
|
|
import proxyAgent from "https-proxy-agent";
|
2021-12-24 01:58:15 +08:00
|
|
|
import { execSync } from "child_process";
|
|
|
|
|
|
|
|
const cwd = process.cwd();
|
2022-04-24 15:35:30 +08:00
|
|
|
const TEMP_DIR = path.join(cwd, "node_modules/.verge");
|
2022-03-09 20:14:15 +08:00
|
|
|
const FORCE = process.argv.includes("--force");
|
2022-11-22 20:44:44 +08:00
|
|
|
|
2023-11-30 22:46:09 +08:00
|
|
|
const PLATFORM_MAP = {
|
|
|
|
"x86_64-pc-windows-msvc": "win32",
|
2024-02-26 13:31:51 +08:00
|
|
|
"i686-pc-windows-msvc": "win32",
|
2023-11-30 22:46:09 +08:00
|
|
|
"aarch64-pc-windows-msvc": "win32",
|
|
|
|
"x86_64-apple-darwin": "darwin",
|
|
|
|
"aarch64-apple-darwin": "darwin",
|
|
|
|
"x86_64-unknown-linux-gnu": "linux",
|
2024-02-26 13:31:51 +08:00
|
|
|
"i686-unknown-linux-gnu": "linux",
|
2023-11-30 22:46:09 +08:00
|
|
|
"aarch64-unknown-linux-gnu": "linux",
|
2023-12-01 11:03:18 +08:00
|
|
|
"armv7-unknown-linux-gnueabihf": "linux",
|
2024-03-15 21:14:05 +08:00
|
|
|
"riscv64gc-unknown-linux-gnu": "linux",
|
2024-01-17 22:30:51 +08:00
|
|
|
"loongarch64-unknown-linux-gnu": "linux",
|
2023-11-30 22:46:09 +08:00
|
|
|
};
|
|
|
|
const ARCH_MAP = {
|
|
|
|
"x86_64-pc-windows-msvc": "x64",
|
2024-02-26 13:31:51 +08:00
|
|
|
"i686-pc-windows-msvc": "ia32",
|
2023-11-30 22:46:09 +08:00
|
|
|
"aarch64-pc-windows-msvc": "arm64",
|
|
|
|
"x86_64-apple-darwin": "x64",
|
|
|
|
"aarch64-apple-darwin": "arm64",
|
|
|
|
"x86_64-unknown-linux-gnu": "x64",
|
2024-02-26 13:31:51 +08:00
|
|
|
"i686-unknown-linux-gnu": "ia32",
|
2023-11-30 22:46:09 +08:00
|
|
|
"aarch64-unknown-linux-gnu": "arm64",
|
2023-12-01 11:03:18 +08:00
|
|
|
"armv7-unknown-linux-gnueabihf": "arm",
|
2024-03-15 21:14:05 +08:00
|
|
|
"riscv64gc-unknown-linux-gnu": "riscv64",
|
2024-01-17 22:30:51 +08:00
|
|
|
"loongarch64-unknown-linux-gnu": "loong64",
|
2023-11-30 22:46:09 +08:00
|
|
|
};
|
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
const arg1 = process.argv.slice(2)[0];
|
|
|
|
const arg2 = process.argv.slice(2)[1];
|
|
|
|
const target = arg1 === "--force" ? arg2 : arg1;
|
2023-11-30 22:46:09 +08:00
|
|
|
const { platform, arch } = target
|
|
|
|
? { platform: PLATFORM_MAP[target], arch: ARCH_MAP[target] }
|
|
|
|
: process;
|
2021-12-29 01:01:09 +08:00
|
|
|
|
2023-11-30 22:46:09 +08:00
|
|
|
const SIDECAR_HOST = target
|
|
|
|
? target
|
|
|
|
: execSync("rustc -vV")
|
|
|
|
.toString()
|
|
|
|
.match(/(?<=host: ).+(?=\s*)/g)[0];
|
2021-12-24 01:58:15 +08:00
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
/* ======= clash meta alpha======= */
|
2023-12-23 12:09:19 +08:00
|
|
|
const META_ALPHA_VERSION_URL =
|
2023-12-03 14:26:03 +08:00
|
|
|
"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;
|
2022-11-22 20:44:44 +08:00
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
const META_ALPHA_MAP = {
|
2023-12-04 06:00:31 +08:00
|
|
|
"win32-x64": "mihomo-windows-amd64-compatible",
|
2024-02-26 13:31:51 +08:00
|
|
|
"win32-ia32": "mihomo-windows-386",
|
2023-12-03 14:26:03 +08:00
|
|
|
"win32-arm64": "mihomo-windows-arm64",
|
2024-05-19 19:30:53 +08:00
|
|
|
"darwin-x64": "mihomo-darwin-amd64-compatible",
|
2023-12-03 14:26:03 +08:00
|
|
|
"darwin-arm64": "mihomo-darwin-arm64",
|
2023-12-04 11:38:54 +08:00
|
|
|
"linux-x64": "mihomo-linux-amd64-compatible",
|
2024-02-26 13:31:51 +08:00
|
|
|
"linux-ia32": "mihomo-linux-386",
|
2023-12-03 14:26:03 +08:00
|
|
|
"linux-arm64": "mihomo-linux-arm64",
|
|
|
|
"linux-arm": "mihomo-linux-armv7",
|
2024-03-15 21:14:05 +08:00
|
|
|
"linux-riscv64": "mihomo-linux-riscv64",
|
2024-01-17 22:30:51 +08:00
|
|
|
"linux-loong64": "mihomo-linux-loong64",
|
2023-12-03 14:26:03 +08:00
|
|
|
};
|
|
|
|
|
2023-12-23 12:09:19 +08:00
|
|
|
// Fetch the latest alpha release version from the version.txt file
|
|
|
|
async function getLatestAlphaVersion() {
|
2023-12-15 20:38:17 +08:00
|
|
|
const options = {};
|
|
|
|
|
|
|
|
const httpProxy =
|
|
|
|
process.env.HTTP_PROXY ||
|
|
|
|
process.env.http_proxy ||
|
|
|
|
process.env.HTTPS_PROXY ||
|
|
|
|
process.env.https_proxy;
|
|
|
|
|
|
|
|
if (httpProxy) {
|
|
|
|
options.agent = proxyAgent(httpProxy);
|
|
|
|
}
|
2023-12-03 14:26:03 +08:00
|
|
|
try {
|
2023-12-23 12:09:19 +08:00
|
|
|
const response = await fetch(META_ALPHA_VERSION_URL, {
|
|
|
|
...options,
|
|
|
|
method: "GET",
|
|
|
|
});
|
2023-12-03 14:26:03 +08:00
|
|
|
let v = await response.text();
|
|
|
|
META_ALPHA_VERSION = v.trim(); // Trim to remove extra whitespaces
|
2023-12-23 12:09:19 +08:00
|
|
|
console.log(`Latest alpha version: ${META_ALPHA_VERSION}`);
|
2023-12-03 14:26:03 +08:00
|
|
|
} catch (error) {
|
2023-12-23 12:09:19 +08:00
|
|
|
console.error("Error fetching latest alpha version:", error.message);
|
2023-12-03 14:26:03 +08:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2022-11-22 20:44:44 +08:00
|
|
|
}
|
2022-05-16 01:52:50 +08:00
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
/* ======= clash meta stable ======= */
|
2023-12-23 12:09:19 +08:00
|
|
|
const META_VERSION_URL =
|
2024-04-30 09:42:25 +08:00
|
|
|
"https://github.com/MetaCubeX/mihomo/releases/latest/download/version.txt";
|
2024-05-19 13:00:27 +08:00
|
|
|
const META_URL_PREFIX = `https://github.com/MetaCubeX/mihomo/releases/download`;
|
2023-12-23 12:09:19 +08:00
|
|
|
let META_VERSION;
|
2023-11-10 11:26:05 +08:00
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
const META_MAP = {
|
2023-12-04 06:00:31 +08:00
|
|
|
"win32-x64": "mihomo-windows-amd64-compatible",
|
2024-02-26 13:31:51 +08:00
|
|
|
"win32-ia32": "mihomo-windows-386",
|
2023-12-03 14:26:03 +08:00
|
|
|
"win32-arm64": "mihomo-windows-arm64",
|
2024-05-19 19:30:53 +08:00
|
|
|
"darwin-x64": "mihomo-darwin-amd64-compatible",
|
2023-12-03 14:26:03 +08:00
|
|
|
"darwin-arm64": "mihomo-darwin-arm64",
|
2023-12-04 11:38:54 +08:00
|
|
|
"linux-x64": "mihomo-linux-amd64-compatible",
|
2024-02-26 13:31:51 +08:00
|
|
|
"linux-ia32": "mihomo-linux-386",
|
2023-12-03 14:26:03 +08:00
|
|
|
"linux-arm64": "mihomo-linux-arm64",
|
|
|
|
"linux-arm": "mihomo-linux-armv7",
|
2024-03-15 21:14:05 +08:00
|
|
|
"linux-riscv64": "mihomo-linux-riscv64",
|
2024-01-17 22:30:51 +08:00
|
|
|
"linux-loong64": "mihomo-linux-loong64",
|
2023-12-03 14:26:03 +08:00
|
|
|
};
|
2023-11-10 11:26:05 +08:00
|
|
|
|
2023-12-23 12:09:19 +08:00
|
|
|
// Fetch the latest release version from the version.txt file
|
|
|
|
async function getLatestReleaseVersion() {
|
|
|
|
const options = {};
|
|
|
|
|
|
|
|
const httpProxy =
|
|
|
|
process.env.HTTP_PROXY ||
|
|
|
|
process.env.http_proxy ||
|
|
|
|
process.env.HTTPS_PROXY ||
|
|
|
|
process.env.https_proxy;
|
|
|
|
|
|
|
|
if (httpProxy) {
|
|
|
|
options.agent = proxyAgent(httpProxy);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const response = await fetch(META_VERSION_URL, {
|
|
|
|
...options,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
/*
|
|
|
|
* check available
|
|
|
|
*/
|
|
|
|
if (!META_MAP[`${platform}-${arch}`]) {
|
|
|
|
throw new Error(
|
|
|
|
`clash meta alpha unsupported platform "${platform}-${arch}"`
|
|
|
|
);
|
2023-11-10 11:26:05 +08:00
|
|
|
}
|
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
if (!META_ALPHA_MAP[`${platform}-${arch}`]) {
|
|
|
|
throw new Error(
|
|
|
|
`clash meta alpha unsupported platform "${platform}-${arch}"`
|
|
|
|
);
|
|
|
|
}
|
2023-07-11 13:25:55 +08:00
|
|
|
|
2023-12-03 14:26:03 +08:00
|
|
|
/**
|
|
|
|
* core info
|
|
|
|
*/
|
|
|
|
function clashMetaAlpha() {
|
|
|
|
const name = META_ALPHA_MAP[`${platform}-${arch}`];
|
2023-07-11 13:25:55 +08:00
|
|
|
const isWin = platform === "win32";
|
|
|
|
const urlExt = isWin ? "zip" : "gz";
|
2023-12-03 14:26:03 +08:00
|
|
|
const downloadURL = `${META_ALPHA_URL_PREFIX}/${name}-${META_ALPHA_VERSION}.${urlExt}`;
|
2023-07-11 13:25:55 +08:00
|
|
|
const exeFile = `${name}${isWin ? ".exe" : ""}`;
|
2023-12-03 14:26:03 +08:00
|
|
|
const zipFile = `${name}-${META_ALPHA_VERSION}.${urlExt}`;
|
2023-07-11 13:25:55 +08:00
|
|
|
|
|
|
|
return {
|
2023-12-03 14:26:03 +08:00
|
|
|
name: "clash-meta-alpha",
|
|
|
|
targetFile: `clash-meta-alpha-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
|
2023-07-11 13:25:55 +08:00
|
|
|
exeFile,
|
|
|
|
zipFile,
|
|
|
|
downloadURL,
|
|
|
|
};
|
|
|
|
}
|
2023-12-03 14:26:03 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
function clashMeta() {
|
|
|
|
const name = META_MAP[`${platform}-${arch}`];
|
2022-05-16 01:52:50 +08:00
|
|
|
const isWin = platform === "win32";
|
2023-12-01 02:44:18 +08:00
|
|
|
const urlExt = isWin ? "zip" : "gz";
|
2023-12-03 14:26:03 +08:00
|
|
|
const downloadURL = `${META_URL_PREFIX}/${META_VERSION}/${name}-${META_VERSION}.${urlExt}`;
|
2022-11-22 20:44:44 +08:00
|
|
|
const exeFile = `${name}${isWin ? ".exe" : ""}`;
|
2023-12-01 02:44:18 +08:00
|
|
|
const zipFile = `${name}-${META_VERSION}.${urlExt}`;
|
2022-11-22 20:44:44 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
name: "clash-meta",
|
|
|
|
targetFile: `clash-meta-${SIDECAR_HOST}${isWin ? ".exe" : ""}`,
|
|
|
|
exeFile,
|
|
|
|
zipFile,
|
|
|
|
downloadURL,
|
|
|
|
};
|
2022-05-16 01:52:50 +08:00
|
|
|
}
|
2021-12-24 01:58:15 +08:00
|
|
|
/**
|
2022-11-22 20:44:44 +08:00
|
|
|
* download sidecar and rename
|
2021-12-24 01:58:15 +08:00
|
|
|
*/
|
2022-11-22 20:44:44 +08:00
|
|
|
async function resolveSidecar(binInfo) {
|
|
|
|
const { name, targetFile, zipFile, exeFile, downloadURL } = binInfo;
|
2022-05-16 01:52:50 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
const sidecarDir = path.join(cwd, "src-tauri", "sidecar");
|
|
|
|
const sidecarPath = path.join(sidecarDir, targetFile);
|
2022-05-16 01:52:50 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
await fs.mkdirp(sidecarDir);
|
|
|
|
if (!FORCE && (await fs.pathExists(sidecarPath))) return;
|
2022-05-16 01:52:50 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
const tempDir = path.join(TEMP_DIR, name);
|
|
|
|
const tempZip = path.join(tempDir, zipFile);
|
|
|
|
const tempExe = path.join(tempDir, exeFile);
|
2022-05-16 01:52:50 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
await fs.mkdirp(tempDir);
|
2023-07-11 13:25:55 +08:00
|
|
|
try {
|
2023-07-23 13:11:17 +08:00
|
|
|
if (!(await fs.pathExists(tempZip))) {
|
2023-07-11 13:25:55 +08:00
|
|
|
await downloadFile(downloadURL, tempZip);
|
2023-07-23 13:11:17 +08:00
|
|
|
}
|
2023-07-11 13:25:55 +08:00
|
|
|
|
|
|
|
if (zipFile.endsWith(".zip")) {
|
|
|
|
const zip = new AdmZip(tempZip);
|
|
|
|
zip.getEntries().forEach((entry) => {
|
|
|
|
console.log(`[DEBUG]: "${name}" entry name`, entry.entryName);
|
|
|
|
});
|
|
|
|
zip.extractAllTo(tempDir, true);
|
|
|
|
await fs.rename(tempExe, sidecarPath);
|
|
|
|
console.log(`[INFO]: "${name}" unzip finished`);
|
2023-11-28 07:49:44 +08:00
|
|
|
} else if (zipFile.endsWith(".tgz")) {
|
|
|
|
// tgz
|
|
|
|
await fs.mkdirp(tempDir);
|
|
|
|
await tar.extract({
|
|
|
|
cwd: tempDir,
|
|
|
|
file: tempZip,
|
|
|
|
//strip: 1, // 可能需要根据实际的 .tgz 文件结构调整
|
|
|
|
});
|
|
|
|
const files = await fs.readdir(tempDir);
|
|
|
|
console.log(`[DEBUG]: "${name}" files in tempDir:`, files);
|
|
|
|
const extractedFile = files.find((file) => file.startsWith("虚空终端-"));
|
|
|
|
if (extractedFile) {
|
|
|
|
const extractedFilePath = path.join(tempDir, extractedFile);
|
|
|
|
await fs.rename(extractedFilePath, sidecarPath);
|
|
|
|
console.log(`[INFO]: "${name}" file renamed to "${sidecarPath}"`);
|
|
|
|
execSync(`chmod 755 ${sidecarPath}`);
|
|
|
|
console.log(`[INFO]: "${name}" chmod binary finished`);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Expected file not found in ${tempDir}`);
|
|
|
|
}
|
2023-07-11 13:25:55 +08:00
|
|
|
} else {
|
|
|
|
// gz
|
|
|
|
const readStream = fs.createReadStream(tempZip);
|
|
|
|
const writeStream = fs.createWriteStream(sidecarPath);
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
const onError = (error) => {
|
2023-07-23 13:11:17 +08:00
|
|
|
console.error(`[ERROR]: "${name}" gz failed:`, error.message);
|
2023-07-11 13:25:55 +08:00
|
|
|
reject(error);
|
|
|
|
};
|
|
|
|
readStream
|
|
|
|
.pipe(zlib.createGunzip().on("error", onError))
|
|
|
|
.pipe(writeStream)
|
|
|
|
.on("finish", () => {
|
|
|
|
console.log(`[INFO]: "${name}" gunzip finished`);
|
|
|
|
execSync(`chmod 755 ${sidecarPath}`);
|
|
|
|
console.log(`[INFO]: "${name}" chmod binary finished`);
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
.on("error", onError);
|
2022-05-16 01:52:50 +08:00
|
|
|
});
|
2023-07-11 13:25:55 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2023-07-23 13:11:17 +08:00
|
|
|
// 需要删除文件
|
|
|
|
await fs.remove(sidecarPath);
|
2023-07-11 13:25:55 +08:00
|
|
|
throw err;
|
|
|
|
} finally {
|
|
|
|
// delete temp dir
|
|
|
|
await fs.remove(tempDir);
|
2021-12-29 01:01:09 +08:00
|
|
|
}
|
2023-07-11 13:25:55 +08:00
|
|
|
}
|
2021-12-24 01:58:15 +08:00
|
|
|
|
2022-04-24 15:35:30 +08:00
|
|
|
/**
|
2022-11-22 20:44:44 +08:00
|
|
|
* download the file to the resources dir
|
2022-04-24 15:35:30 +08:00
|
|
|
*/
|
2022-11-22 20:44:44 +08:00
|
|
|
async function resolveResource(binInfo) {
|
|
|
|
const { file, downloadURL } = binInfo;
|
2022-04-24 15:35:30 +08:00
|
|
|
|
2022-04-27 15:46:44 +08:00
|
|
|
const resDir = path.join(cwd, "src-tauri/resources");
|
2022-11-22 20:44:44 +08:00
|
|
|
const targetPath = path.join(resDir, file);
|
2022-04-24 15:35:30 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
if (!FORCE && (await fs.pathExists(targetPath))) return;
|
2022-11-10 22:58:34 +08:00
|
|
|
|
|
|
|
await fs.mkdirp(resDir);
|
2022-11-22 20:44:44 +08:00
|
|
|
await downloadFile(downloadURL, targetPath);
|
2022-11-10 22:58:34 +08:00
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
console.log(`[INFO]: ${file} finished`);
|
2022-11-10 22:58:34 +08:00
|
|
|
}
|
|
|
|
|
2021-12-24 01:58:15 +08:00
|
|
|
/**
|
|
|
|
* download file and save to `path`
|
|
|
|
*/
|
|
|
|
async function downloadFile(url, path) {
|
2022-04-17 00:37:21 +08:00
|
|
|
const options = {};
|
|
|
|
|
|
|
|
const httpProxy =
|
|
|
|
process.env.HTTP_PROXY ||
|
|
|
|
process.env.http_proxy ||
|
|
|
|
process.env.HTTPS_PROXY ||
|
|
|
|
process.env.https_proxy;
|
|
|
|
|
|
|
|
if (httpProxy) {
|
|
|
|
options.agent = proxyAgent(httpProxy);
|
|
|
|
}
|
|
|
|
|
2021-12-24 01:58:15 +08:00
|
|
|
const response = await fetch(url, {
|
2022-04-17 00:37:21 +08:00
|
|
|
...options,
|
2021-12-24 01:58:15 +08:00
|
|
|
method: "GET",
|
|
|
|
headers: { "Content-Type": "application/octet-stream" },
|
|
|
|
});
|
|
|
|
const buffer = await response.arrayBuffer();
|
|
|
|
await fs.writeFile(path, new Uint8Array(buffer));
|
2021-12-29 01:01:09 +08:00
|
|
|
|
|
|
|
console.log(`[INFO]: download finished "${url}"`);
|
2021-12-24 01:58:15 +08:00
|
|
|
}
|
|
|
|
|
2024-02-18 10:19:54 +08:00
|
|
|
// SimpleSC.dll
|
|
|
|
const resolvePlugin = async () => {
|
|
|
|
const url =
|
|
|
|
"https://nsis.sourceforge.io/mediawiki/images/e/ef/NSIS_Simple_Service_Plugin_Unicode_1.30.zip";
|
|
|
|
|
|
|
|
const tempDir = path.join(TEMP_DIR, "SimpleSC");
|
|
|
|
const tempZip = path.join(
|
|
|
|
tempDir,
|
|
|
|
"NSIS_Simple_Service_Plugin_Unicode_1.30.zip"
|
|
|
|
);
|
|
|
|
const tempDll = path.join(tempDir, "SimpleSC.dll");
|
|
|
|
const pluginDir = path.join(process.env.APPDATA, "Local/NSIS");
|
|
|
|
const pluginPath = path.join(pluginDir, "SimpleSC.dll");
|
|
|
|
await fs.mkdirp(pluginDir);
|
|
|
|
await fs.mkdirp(tempDir);
|
|
|
|
if (!FORCE && (await fs.pathExists(pluginPath))) return;
|
|
|
|
try {
|
|
|
|
if (!(await fs.pathExists(tempZip))) {
|
|
|
|
await downloadFile(url, tempZip);
|
|
|
|
}
|
|
|
|
const zip = new AdmZip(tempZip);
|
|
|
|
zip.getEntries().forEach((entry) => {
|
|
|
|
console.log(`[DEBUG]: "SimpleSC" entry name`, entry.entryName);
|
|
|
|
});
|
|
|
|
zip.extractAllTo(tempDir, true);
|
|
|
|
await fs.copyFile(tempDll, pluginPath);
|
|
|
|
console.log(`[INFO]: "SimpleSC" unzip finished`);
|
|
|
|
} finally {
|
|
|
|
await fs.remove(tempDir);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-31 21:44:34 +08:00
|
|
|
// service chmod
|
|
|
|
const resolveServicePermission = async () => {
|
2024-03-31 16:16:23 +08:00
|
|
|
const serviceExecutables = [
|
|
|
|
"clash-verge-service",
|
|
|
|
"install-service",
|
|
|
|
"uninstall-service",
|
|
|
|
];
|
|
|
|
const resDir = path.join(cwd, "src-tauri/resources");
|
2024-03-31 16:37:33 +08:00
|
|
|
for (let f of serviceExecutables) {
|
2024-03-31 16:16:23 +08:00
|
|
|
const targetPath = path.join(resDir, f);
|
|
|
|
if (await fs.pathExists(targetPath)) {
|
|
|
|
execSync(`chmod 755 ${targetPath}`);
|
|
|
|
console.log(`[INFO]: "${targetPath}" chmod finished`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-22 20:44:44 +08:00
|
|
|
/**
|
|
|
|
* main
|
|
|
|
*/
|
2023-12-15 20:38:17 +08:00
|
|
|
|
|
|
|
const SERVICE_URL = `https://github.com/clash-verge-rev/clash-verge-service/releases/download/${SIDECAR_HOST}`;
|
2022-11-22 20:44:44 +08:00
|
|
|
|
2024-03-31 21:44:34 +08:00
|
|
|
const resolveService = () => {
|
|
|
|
let ext = platform === "win32" ? ".exe" : "";
|
2022-11-22 20:44:44 +08:00
|
|
|
resolveResource({
|
2024-03-31 21:44:34 +08:00
|
|
|
file: "clash-verge-service" + ext,
|
|
|
|
downloadURL: `${SERVICE_URL}/clash-verge-service${ext}`,
|
2024-03-31 16:16:23 +08:00
|
|
|
});
|
|
|
|
};
|
2024-03-31 21:44:34 +08:00
|
|
|
|
|
|
|
const resolveInstall = () => {
|
|
|
|
let ext = platform === "win32" ? ".exe" : "";
|
2022-11-22 20:44:44 +08:00
|
|
|
resolveResource({
|
2024-03-31 21:44:34 +08:00
|
|
|
file: "install-service" + ext,
|
2024-04-03 23:18:10 +08:00
|
|
|
downloadURL: `${SERVICE_URL}/install-service${ext}`,
|
2022-11-22 20:44:44 +08:00
|
|
|
});
|
2024-03-31 21:44:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const resolveUninstall = () => {
|
|
|
|
let ext = platform === "win32" ? ".exe" : "";
|
2024-03-31 16:16:23 +08:00
|
|
|
resolveResource({
|
2024-03-31 21:44:34 +08:00
|
|
|
file: "uninstall-service" + ext,
|
|
|
|
downloadURL: `${SERVICE_URL}/uninstall-service${ext}`,
|
2024-03-31 16:16:23 +08:00
|
|
|
});
|
2024-03-31 21:44:34 +08:00
|
|
|
};
|
|
|
|
|
2024-03-11 22:03:45 +08:00
|
|
|
const resolveSetDnsScript = () =>
|
|
|
|
resolveResource({
|
|
|
|
file: "set_dns.sh",
|
|
|
|
downloadURL: `https://github.com/clash-verge-rev/set-dns-script/releases/download/script/set_dns.sh`,
|
|
|
|
});
|
|
|
|
const resolveUnSetDnsScript = () =>
|
|
|
|
resolveResource({
|
|
|
|
file: "unset_dns.sh",
|
|
|
|
downloadURL: `https://github.com/clash-verge-rev/set-dns-script/releases/download/script/unset_dns.sh`,
|
|
|
|
});
|
2022-11-22 20:44:44 +08:00
|
|
|
const resolveMmdb = () =>
|
|
|
|
resolveResource({
|
|
|
|
file: "Country.mmdb",
|
2023-11-22 02:56:47 +08:00
|
|
|
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb`,
|
2022-11-22 20:44:44 +08:00
|
|
|
});
|
|
|
|
const resolveGeosite = () =>
|
|
|
|
resolveResource({
|
|
|
|
file: "geosite.dat",
|
2023-08-05 13:42:37 +08:00
|
|
|
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat`,
|
2022-11-10 22:58:34 +08:00
|
|
|
});
|
2022-11-22 20:44:44 +08:00
|
|
|
const resolveGeoIP = () =>
|
|
|
|
resolveResource({
|
|
|
|
file: "geoip.dat",
|
2023-08-05 13:42:37 +08:00
|
|
|
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat`,
|
2022-11-10 22:58:34 +08:00
|
|
|
});
|
2023-11-22 16:15:41 +08:00
|
|
|
const resolveEnableLoopback = () =>
|
|
|
|
resolveResource({
|
|
|
|
file: "enableLoopback.exe",
|
|
|
|
downloadURL: `https://github.com/Kuingsmile/uwp-tool/releases/download/latest/enableLoopback.exe`,
|
|
|
|
});
|
2022-11-22 20:44:44 +08:00
|
|
|
|
|
|
|
const tasks = [
|
2023-11-22 02:56:47 +08:00
|
|
|
// { name: "clash", func: resolveClash, retry: 5 },
|
2023-12-03 14:26:03 +08:00
|
|
|
{
|
|
|
|
name: "clash-meta-alpha",
|
2023-12-23 12:09:19 +08:00
|
|
|
func: () =>
|
|
|
|
getLatestAlphaVersion().then(() => resolveSidecar(clashMetaAlpha())),
|
2023-12-03 14:26:03 +08:00
|
|
|
retry: 5,
|
|
|
|
},
|
2023-12-01 02:44:18 +08:00
|
|
|
{
|
|
|
|
name: "clash-meta",
|
2023-12-23 12:09:19 +08:00
|
|
|
func: () =>
|
|
|
|
getLatestReleaseVersion().then(() => resolveSidecar(clashMeta())),
|
2023-12-01 02:44:18 +08:00
|
|
|
retry: 5,
|
|
|
|
},
|
2024-02-18 10:19:54 +08:00
|
|
|
{ name: "plugin", func: resolvePlugin, retry: 5, winOnly: true },
|
2024-03-31 21:44:34 +08:00
|
|
|
{ name: "service", func: resolveService, retry: 5 },
|
|
|
|
{ name: "install", func: resolveInstall, retry: 5 },
|
|
|
|
{ name: "uninstall", func: resolveUninstall, retry: 5 },
|
2024-03-11 22:10:20 +08:00
|
|
|
{ name: "set_dns_script", func: resolveSetDnsScript, retry: 5 },
|
|
|
|
{ name: "unset_dns_script", func: resolveUnSetDnsScript, retry: 5 },
|
2022-11-22 20:44:44 +08:00
|
|
|
{ name: "mmdb", func: resolveMmdb, retry: 5 },
|
|
|
|
{ name: "geosite", func: resolveGeosite, retry: 5 },
|
|
|
|
{ name: "geoip", func: resolveGeoIP, retry: 5 },
|
2023-11-22 16:15:41 +08:00
|
|
|
{
|
|
|
|
name: "enableLoopback",
|
|
|
|
func: resolveEnableLoopback,
|
|
|
|
retry: 5,
|
|
|
|
winOnly: true,
|
|
|
|
},
|
2024-03-31 16:16:23 +08:00
|
|
|
{
|
2024-03-31 21:44:34 +08:00
|
|
|
name: "service_chmod",
|
|
|
|
func: resolveServicePermission,
|
2024-03-31 16:16:23 +08:00
|
|
|
retry: 1,
|
2024-03-31 21:44:34 +08:00
|
|
|
unixOnly: true,
|
2024-03-31 16:16:23 +08:00
|
|
|
},
|
2022-11-22 20:44:44 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
async function runTask() {
|
|
|
|
const task = tasks.shift();
|
|
|
|
if (!task) return;
|
2024-03-31 21:44:34 +08:00
|
|
|
if (task.winOnly && platform !== "win32") return runTask();
|
|
|
|
if (task.linuxOnly && platform !== "linux") return runTask();
|
|
|
|
if (task.unixOnly && platform === "win32") return runTask();
|
2022-11-22 20:44:44 +08:00
|
|
|
|
|
|
|
for (let i = 0; i < task.retry; i++) {
|
|
|
|
try {
|
|
|
|
await task.func();
|
|
|
|
break;
|
|
|
|
} catch (err) {
|
2023-07-23 13:11:17 +08:00
|
|
|
console.error(`[ERROR]: task::${task.name} try ${i} ==`, err.message);
|
|
|
|
if (i === task.retry - 1) throw err;
|
2022-11-22 20:44:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return runTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
runTask();
|
|
|
|
runTask();
|