feat: add rustfmt configuration and CI workflow for code formatting

refactor: streamline formatting workflow by removing unused taplo steps and clarifying directory change

refactor: remove unnecessary directory change step in formatting workflow
This commit is contained in:
Tunglies
2025-06-06 21:11:14 +08:00
parent 689042df60
commit 09969d95de
89 changed files with 2630 additions and 2008 deletions

View File

@@ -1,7 +1,11 @@
import { useTranslation } from "react-i18next";
import { useLockFn } from "ahooks";
import { showNotice } from "@/services/noticeService";
import { installService, isServiceAvailable, restartCore } from "@/services/cmds";
import {
installService,
isServiceAvailable,
restartCore,
} from "@/services/cmds";
import { useSystemState } from "@/hooks/use-system-state";
import { mutate } from "swr";
@@ -11,16 +15,16 @@ export function useServiceInstaller() {
const installServiceAndRestartCore = useLockFn(async () => {
try {
showNotice('info', t("Installing Service..."));
showNotice("info", t("Installing Service..."));
await installService();
showNotice('success', t("Service Installed Successfully"));
showNotice("success", t("Service Installed Successfully"));
showNotice('info', t("Waiting for service to be ready..."));
showNotice("info", t("Waiting for service to be ready..."));
let serviceReady = false;
for (let i = 0; i < 5; i++) {
try {
// 等待1秒再检查
await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 1000));
const isAvailable = await isServiceAvailable();
if (isAvailable) {
serviceReady = true;
@@ -29,52 +33,86 @@ export function useServiceInstaller() {
}
// 最后一次尝试不显示重试信息
if (i < 4) {
showNotice('info', t("Service not ready, retrying attempt {count}/{total}...", { count: i + 1, total: 5 }));
showNotice(
"info",
t("Service not ready, retrying attempt {count}/{total}...", {
count: i + 1,
total: 5,
}),
);
}
} catch (error) {
console.error(t("Error checking service status:"), error);
if (i < 4) {
showNotice('error', t("Failed to check service status, retrying attempt {count}/{total}...", { count: i + 1, total: 5 }));
showNotice(
"error",
t(
"Failed to check service status, retrying attempt {count}/{total}...",
{ count: i + 1, total: 5 },
),
);
}
}
}
if (!serviceReady) {
showNotice('info', t("Service did not become ready after attempts. Proceeding with core restart."));
showNotice(
"info",
t(
"Service did not become ready after attempts. Proceeding with core restart.",
),
);
}
showNotice('info', t("Restarting Core..."));
showNotice("info", t("Restarting Core..."));
await restartCore();
// 核心重启后,再次确认并更新相关状态
await mutateRunningMode();
await mutateRunningMode();
const finalServiceStatus = await isServiceAvailable();
mutate("isServiceAvailable", finalServiceStatus, false);
mutate("isServiceAvailable", finalServiceStatus, false);
if (serviceReady && finalServiceStatus) {
showNotice('success', t("Service is ready and core restarted"));
showNotice("success", t("Service is ready and core restarted"));
} else if (finalServiceStatus) {
showNotice('success', t("Core restarted. Service is now available."));
showNotice("success", t("Core restarted. Service is now available."));
} else if (serviceReady) {
showNotice('info', t("Service was ready, but core restart might have issues or service became unavailable. Please check."));
showNotice(
"info",
t(
"Service was ready, but core restart might have issues or service became unavailable. Please check.",
),
);
} else {
showNotice('error', t("Service installation or core restart encountered issues. Service might not be available. Please check system logs."));
showNotice(
"error",
t(
"Service installation or core restart encountered issues. Service might not be available. Please check system logs.",
),
);
}
return finalServiceStatus;
} catch (err: any) {
showNotice('error', err.message || err.toString());
showNotice("error", err.message || err.toString());
// 尝试性回退或最终操作
try {
showNotice('info', t("Attempting to restart core as a fallback..."));
showNotice("info", t("Attempting to restart core as a fallback..."));
await restartCore();
await mutateRunningMode();
await isServiceAvailable().then(status => mutate("isServiceAvailable", status, false));
await isServiceAvailable().then((status) =>
mutate("isServiceAvailable", status, false),
);
} catch (recoveryError: any) {
showNotice('error', t("Fallback core restart also failed: {message}", { message: recoveryError.message }));
showNotice(
"error",
t("Fallback core restart also failed: {message}", {
message: recoveryError.message,
}),
);
}
return false;
}
});
return { installServiceAndRestartCore };
}
}