mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-13 05:20:28 +08:00
build(linux): bundle linux service binaries from sidecar (#6311)
* refactor: prebuild * style: prettier
This commit is contained in:
parent
58047cbbd1
commit
1927b5f957
@ -68,6 +68,11 @@ const SIDECAR_HOST = target
|
|||||||
.toString()
|
.toString()
|
||||||
.match(/(?<=host: ).+(?=\s*)/g)[0];
|
.match(/(?<=host: ).+(?=\s*)/g)[0];
|
||||||
|
|
||||||
|
const RESOURCES_DIR = path.join(cwd, "src-tauri", "resources");
|
||||||
|
const SIDECAR_DIR = path.join(cwd, "src-tauri", "sidecar");
|
||||||
|
// Linux service binaries are bundled as externalBin sidecars (see tauri.linux.conf.json)
|
||||||
|
const SERVICE_DIR = platform === "linux" ? SIDECAR_DIR : RESOURCES_DIR;
|
||||||
|
|
||||||
// =======================
|
// =======================
|
||||||
// Version Cache
|
// Version Cache
|
||||||
// =======================
|
// =======================
|
||||||
@ -369,9 +374,8 @@ async function downloadFile(url, outPath) {
|
|||||||
// =======================
|
// =======================
|
||||||
async function resolveSidecar(binInfo) {
|
async function resolveSidecar(binInfo) {
|
||||||
const { name, targetFile, zipFile, exeFile, downloadURL } = binInfo;
|
const { name, targetFile, zipFile, exeFile, downloadURL } = binInfo;
|
||||||
const sidecarDir = path.join(cwd, "src-tauri", "sidecar");
|
const sidecarPath = path.join(SIDECAR_DIR, targetFile);
|
||||||
const sidecarPath = path.join(sidecarDir, targetFile);
|
await fsp.mkdir(SIDECAR_DIR, { recursive: true });
|
||||||
await fsp.mkdir(sidecarDir, { recursive: true });
|
|
||||||
|
|
||||||
if (!FORCE && fs.existsSync(sidecarPath)) {
|
if (!FORCE && fs.existsSync(sidecarPath)) {
|
||||||
log_success(`"${name}" already exists, skipping download`);
|
log_success(`"${name}" already exists, skipping download`);
|
||||||
@ -460,9 +464,9 @@ async function resolveSidecar(binInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function resolveResource(binInfo) {
|
async function resolveResource(binInfo) {
|
||||||
const { file, downloadURL, localPath } = binInfo;
|
const { file, downloadURL, localPath, dir } = binInfo;
|
||||||
const resDir = path.join(cwd, "src-tauri/resources");
|
const baseDir = dir ?? RESOURCES_DIR;
|
||||||
const targetPath = path.join(resDir, file);
|
const targetPath = path.join(baseDir, file);
|
||||||
|
|
||||||
if (!FORCE && fs.existsSync(targetPath) && !downloadURL && !localPath) {
|
if (!FORCE && fs.existsSync(targetPath) && !downloadURL && !localPath) {
|
||||||
log_success(`"${file}" already exists, skipping`);
|
log_success(`"${file}" already exists, skipping`);
|
||||||
@ -474,7 +478,7 @@ async function resolveResource(binInfo) {
|
|||||||
log_success(`"${file}" already exists, skipping download`);
|
log_success(`"${file}" already exists, skipping download`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fsp.mkdir(resDir, { recursive: true });
|
await fsp.mkdir(baseDir, { recursive: true });
|
||||||
await downloadFile(downloadURL, targetPath);
|
await downloadFile(downloadURL, targetPath);
|
||||||
await updateHashCache(targetPath);
|
await updateHashCache(targetPath);
|
||||||
}
|
}
|
||||||
@ -483,7 +487,7 @@ async function resolveResource(binInfo) {
|
|||||||
if (!(await hasFileChanged(localPath, targetPath))) {
|
if (!(await hasFileChanged(localPath, targetPath))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fsp.mkdir(resDir, { recursive: true });
|
await fsp.mkdir(baseDir, { recursive: true });
|
||||||
await fsp.copyFile(localPath, targetPath);
|
await fsp.copyFile(localPath, targetPath);
|
||||||
await updateHashCache(targetPath);
|
await updateHashCache(targetPath);
|
||||||
log_success(`Copied file: ${file}`);
|
log_success(`Copied file: ${file}`);
|
||||||
@ -545,12 +549,11 @@ const resolveServicePermission = async () => {
|
|||||||
"clash-verge-service-install*",
|
"clash-verge-service-install*",
|
||||||
"clash-verge-service-uninstall*",
|
"clash-verge-service-uninstall*",
|
||||||
];
|
];
|
||||||
const resDir = path.join(cwd, "src-tauri/resources");
|
|
||||||
const hashCache = await loadHashCache();
|
const hashCache = await loadHashCache();
|
||||||
let hasChanges = false;
|
let hasChanges = false;
|
||||||
|
|
||||||
for (const f of serviceExecutables) {
|
for (const f of serviceExecutables) {
|
||||||
const files = glob.sync(path.join(resDir, f));
|
const files = glob.sync(path.join(SERVICE_DIR, f));
|
||||||
for (const filePath of files) {
|
for (const filePath of files) {
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
const currentHash = await calculateFileHash(filePath);
|
const currentHash = await calculateFileHash(filePath);
|
||||||
@ -584,6 +587,7 @@ const resolveService = () => {
|
|||||||
const suffix = platform === "linux" ? "-" + SIDECAR_HOST : "";
|
const suffix = platform === "linux" ? "-" + SIDECAR_HOST : "";
|
||||||
return resolveResource({
|
return resolveResource({
|
||||||
file: "clash-verge-service" + suffix + ext,
|
file: "clash-verge-service" + suffix + ext,
|
||||||
|
dir: SERVICE_DIR,
|
||||||
downloadURL: `${SERVICE_URL}/clash-verge-service${ext}`,
|
downloadURL: `${SERVICE_URL}/clash-verge-service${ext}`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -592,6 +596,7 @@ const resolveInstall = () => {
|
|||||||
const suffix = platform === "linux" ? "-" + SIDECAR_HOST : "";
|
const suffix = platform === "linux" ? "-" + SIDECAR_HOST : "";
|
||||||
return resolveResource({
|
return resolveResource({
|
||||||
file: "clash-verge-service-install" + suffix + ext,
|
file: "clash-verge-service-install" + suffix + ext,
|
||||||
|
dir: SERVICE_DIR,
|
||||||
downloadURL: `${SERVICE_URL}/clash-verge-service-install${ext}`,
|
downloadURL: `${SERVICE_URL}/clash-verge-service-install${ext}`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -600,6 +605,7 @@ const resolveUninstall = () => {
|
|||||||
const suffix = platform === "linux" ? "-" + SIDECAR_HOST : "";
|
const suffix = platform === "linux" ? "-" + SIDECAR_HOST : "";
|
||||||
return resolveResource({
|
return resolveResource({
|
||||||
file: "clash-verge-service-uninstall" + suffix + ext,
|
file: "clash-verge-service-uninstall" + suffix + ext,
|
||||||
|
dir: SERVICE_DIR,
|
||||||
downloadURL: `${SERVICE_URL}/clash-verge-service-uninstall${ext}`,
|
downloadURL: `${SERVICE_URL}/clash-verge-service-uninstall${ext}`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -24,9 +24,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"externalBin": [
|
"externalBin": [
|
||||||
"./resources/clash-verge-service",
|
"./sidecar/clash-verge-service",
|
||||||
"./resources/clash-verge-service-install",
|
"./sidecar/clash-verge-service-install",
|
||||||
"./resources/clash-verge-service-uninstall",
|
"./sidecar/clash-verge-service-uninstall",
|
||||||
"./sidecar/verge-mihomo",
|
"./sidecar/verge-mihomo",
|
||||||
"./sidecar/verge-mihomo-alpha"
|
"./sidecar/verge-mihomo-alpha"
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user