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

@@ -50,86 +50,95 @@ const handleNoticeMessage = (
switch (status) {
case "import_sub_url::ok":
navigate("/profile", { state: { current: msg } });
showNotice('success', t("Import Subscription Successful"));
showNotice("success", t("Import Subscription Successful"));
break;
case "import_sub_url::error":
navigate("/profile");
showNotice('error', msg);
showNotice("error", msg);
break;
case "set_config::error":
showNotice('error', msg);
showNotice("error", msg);
break;
case "update_with_clash_proxy":
showNotice('success', `${t("Update with Clash proxy successfully")} ${msg}`);
showNotice(
"success",
`${t("Update with Clash proxy successfully")} ${msg}`,
);
break;
case "update_retry_with_clash":
showNotice('info', t("Update failed, retrying with Clash proxy..."));
showNotice("info", t("Update failed, retrying with Clash proxy..."));
break;
case "update_failed_even_with_clash":
showNotice('error', `${t("Update failed even with Clash proxy")}: ${msg}`);
showNotice(
"error",
`${t("Update failed even with Clash proxy")}: ${msg}`,
);
break;
case "update_failed":
showNotice('error', msg);
showNotice("error", msg);
break;
case "config_validate::boot_error":
showNotice('error', `${t("Boot Config Validation Failed")} ${msg}`);
showNotice("error", `${t("Boot Config Validation Failed")} ${msg}`);
break;
case "config_validate::core_change":
showNotice('error', `${t("Core Change Config Validation Failed")} ${msg}`);
showNotice(
"error",
`${t("Core Change Config Validation Failed")} ${msg}`,
);
break;
case "config_validate::error":
showNotice('error', `${t("Config Validation Failed")} ${msg}`);
showNotice("error", `${t("Config Validation Failed")} ${msg}`);
break;
case "config_validate::process_terminated":
showNotice('error', t("Config Validation Process Terminated"));
showNotice("error", t("Config Validation Process Terminated"));
break;
case "config_validate::stdout_error":
showNotice('error', `${t("Config Validation Failed")} ${msg}`);
showNotice("error", `${t("Config Validation Failed")} ${msg}`);
break;
case "config_validate::script_error":
showNotice('error', `${t("Script File Error")} ${msg}`);
showNotice("error", `${t("Script File Error")} ${msg}`);
break;
case "config_validate::script_syntax_error":
showNotice('error', `${t("Script Syntax Error")} ${msg}`);
showNotice("error", `${t("Script Syntax Error")} ${msg}`);
break;
case "config_validate::script_missing_main":
showNotice('error', `${t("Script Missing Main")} ${msg}`);
showNotice("error", `${t("Script Missing Main")} ${msg}`);
break;
case "config_validate::file_not_found":
showNotice('error', `${t("File Not Found")} ${msg}`);
showNotice("error", `${t("File Not Found")} ${msg}`);
break;
case "config_validate::yaml_syntax_error":
showNotice('error', `${t("YAML Syntax Error")} ${msg}`);
showNotice("error", `${t("YAML Syntax Error")} ${msg}`);
break;
case "config_validate::yaml_read_error":
showNotice('error', `${t("YAML Read Error")} ${msg}`);
showNotice("error", `${t("YAML Read Error")} ${msg}`);
break;
case "config_validate::yaml_mapping_error":
showNotice('error', `${t("YAML Mapping Error")} ${msg}`);
showNotice("error", `${t("YAML Mapping Error")} ${msg}`);
break;
case "config_validate::yaml_key_error":
showNotice('error', `${t("YAML Key Error")} ${msg}`);
showNotice("error", `${t("YAML Key Error")} ${msg}`);
break;
case "config_validate::yaml_error":
showNotice('error', `${t("YAML Error")} ${msg}`);
showNotice("error", `${t("YAML Error")} ${msg}`);
break;
case "config_validate::merge_syntax_error":
showNotice('error', `${t("Merge File Syntax Error")} ${msg}`);
showNotice("error", `${t("Merge File Syntax Error")} ${msg}`);
break;
case "config_validate::merge_mapping_error":
showNotice('error', `${t("Merge File Mapping Error")} ${msg}`);
showNotice("error", `${t("Merge File Mapping Error")} ${msg}`);
break;
case "config_validate::merge_key_error":
showNotice('error', `${t("Merge File Key Error")} ${msg}`);
showNotice("error", `${t("Merge File Key Error")} ${msg}`);
break;
case "config_validate::merge_error":
showNotice('error', `${t("Merge File Error")} ${msg}`);
showNotice("error", `${t("Merge File Error")} ${msg}`);
break;
case "config_core::change_success":
showNotice('success', `${t("Core Changed Successfully")}: ${msg}`);
showNotice("success", `${t("Core Changed Successfully")}: ${msg}`);
break;
case "config_core::change_error":
showNotice('error', `${t("Failed to Change Core")}: ${msg}`);
showNotice("error", `${t("Failed to Change Core")}: ${msg}`);
break;
default: // Optional: Log unhandled statuses
console.warn(`[通知监听 V2] 未处理的状态: ${status}`);
@@ -190,7 +199,6 @@ const Layout = () => {
mutate("getAutotemProxy");
}),
addListener("verge://notice-message", ({ payload }) =>
handleNotice(payload as [string, string]),
),
@@ -276,7 +284,7 @@ const Layout = () => {
return unlisten;
} catch (err) {
console.error("[Layout] 监听启动完成事件失败:", err);
return () => { };
return () => {};
}
};
@@ -298,7 +306,7 @@ const Layout = () => {
const unlistenPromise = listenStartupCompleted();
return () => {
unlistenPromise.then(unlisten => unlisten());
unlistenPromise.then((unlisten) => unlisten());
};
}, []);
@@ -368,11 +376,11 @@ const Layout = () => {
({ palette }) => ({ bgcolor: palette.background.paper }),
OS === "linux"
? {
borderRadius: "8px",
border: "1px solid var(--divider-color)",
width: "calc(100vw - 4px)",
height: "calc(100vh - 4px)",
}
borderRadius: "8px",
border: "1px solid var(--divider-color)",
width: "calc(100vw - 4px)",
height: "calc(100vh - 4px)",
}
: {},
]}
>
@@ -420,8 +428,7 @@ const Layout = () => {
</div>
<div className="layout__right">
<div className="the-bar">
</div>
<div className="the-bar"></div>
<div className="the-content">
{React.cloneElement(routersEles, { key: location.pathname })}

View File

@@ -43,7 +43,7 @@ const ConnectionsPage = () => {
const isDark = theme.palette.mode === "dark";
const [match, setMatch] = useState(() => (_: string) => true);
const [curOrderOpt, setOrderOpt] = useState("Default");
// 使用全局数据
const { connections } = useAppData();
@@ -69,19 +69,21 @@ const ConnectionsPage = () => {
// 使用全局连接数据
const displayData = useMemo(() => {
if (!pageVisible) return initConn;
if (isPaused) {
return frozenData ?? {
uploadTotal: connections.uploadTotal,
downloadTotal: connections.downloadTotal,
connections: connections.data
};
return (
frozenData ?? {
uploadTotal: connections.uploadTotal,
downloadTotal: connections.downloadTotal,
connections: connections.data,
}
);
}
return {
uploadTotal: connections.uploadTotal,
downloadTotal: connections.downloadTotal,
connections: connections.data
connections: connections.data,
};
}, [isPaused, frozenData, connections, pageVisible]);
@@ -113,7 +115,7 @@ const ConnectionsPage = () => {
setFrozenData({
uploadTotal: connections.uploadTotal,
downloadTotal: connections.downloadTotal,
connections: connections.data
connections: connections.data,
});
} else {
setFrozenData(null);

View File

@@ -398,4 +398,4 @@ const ClashModeEnhancedCard = () => {
);
};
export default HomePage;
export default HomePage;

View File

@@ -80,7 +80,7 @@ const ProfilePage = () => {
for (let file of paths) {
if (!file.endsWith(".yaml") && !file.endsWith(".yml")) {
showNotice('error', t("Only YAML Files Supported"));
showNotice("error", t("Only YAML Files Supported"));
continue;
}
const item = {
@@ -145,31 +145,34 @@ const ProfilePage = () => {
try {
// 尝试正常导入
await importProfile(url);
showNotice('success', t("Profile Imported Successfully"));
showNotice("success", t("Profile Imported Successfully"));
setUrl("");
mutateProfiles();
await onEnhance(false);
} catch (err: any) {
// 首次导入失败,尝试使用自身代理
const errmsg = err.message || err.toString();
showNotice('info', t("Import failed, retrying with Clash proxy..."));
showNotice("info", t("Import failed, retrying with Clash proxy..."));
try {
// 使用自身代理尝试导入
await importProfile(url, {
with_proxy: false,
self_proxy: true
self_proxy: true,
});
// 回退导入成功
showNotice('success', t("Profile Imported with Clash proxy"));
showNotice("success", t("Profile Imported with Clash proxy"));
setUrl("");
mutateProfiles();
await onEnhance(false);
} catch (retryErr: any) {
// 回退导入也失败
const retryErrmsg = retryErr?.message || retryErr.toString();
showNotice('error', `${t("Import failed even with Clash proxy")}: ${retryErrmsg}`);
showNotice(
"error",
`${t("Import failed even with Clash proxy")}: ${retryErrmsg}`,
);
}
} finally {
setDisabled(false);
@@ -199,10 +202,10 @@ const ProfilePage = () => {
closeAllConnections();
await activateSelected();
if (notifySuccess && success) {
showNotice('success', t("Profile Switched"), 1000);
showNotice("success", t("Profile Switched"), 1000);
}
} catch (err: any) {
showNotice('error', err?.message || err.toString(), 4000);
showNotice("error", err?.message || err.toString(), 4000);
} finally {
clearTimeout(reset);
setActivatings([]);
@@ -228,10 +231,10 @@ const ProfilePage = () => {
await enhanceProfiles();
mutateLogs();
if (notifySuccess) {
showNotice('success', t("Profile Reactivated"), 1000);
showNotice("success", t("Profile Reactivated"), 1000);
}
} catch (err: any) {
showNotice('error', err.message || err.toString(), 3000);
showNotice("error", err.message || err.toString(), 3000);
} finally {
setActivatings([]);
}
@@ -246,7 +249,7 @@ const ProfilePage = () => {
mutateLogs();
current && (await onEnhance(false));
} catch (err: any) {
showNotice('error', err?.message || err.toString());
showNotice("error", err?.message || err.toString());
} finally {
setActivatings([]);
}
@@ -300,12 +303,12 @@ const ProfilePage = () => {
let timeoutId: ReturnType<typeof setTimeout> | undefined;
const setupListener = async () => {
unlistenPromise = listen<string>('profile-changed', (event) => {
console.log('Profile changed event received:', event.payload);
unlistenPromise = listen<string>("profile-changed", (event) => {
console.log("Profile changed event received:", event.payload);
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
mutateProfiles();
timeoutId = undefined;
@@ -319,7 +322,7 @@ const ProfilePage = () => {
if (timeoutId) {
clearTimeout(timeoutId);
}
unlistenPromise?.then(unlisten => unlisten());
unlistenPromise?.then((unlisten) => unlisten());
};
}, [mutateProfiles, t]);
@@ -398,7 +401,7 @@ const ProfilePage = () => {
<ClearRounded fontSize="inherit" />
</IconButton>
),
}
},
}}
/>
<LoadingButton

View File

@@ -20,8 +20,8 @@ const ProxyPage = () => {
revalidateOnFocus: false,
revalidateIfStale: true,
dedupingInterval: 1000,
errorRetryInterval: 5000
}
errorRetryInterval: 5000,
},
);
const { verge } = useVerge();

View File

@@ -15,7 +15,7 @@ const SettingPage = () => {
const { t } = useTranslation();
const onError = (err: any) => {
showNotice('error', err?.message || err.toString());
showNotice("error", err?.message || err.toString());
};
const toGithubRepo = useLockFn(() => {

View File

@@ -130,7 +130,9 @@ const UnlockPage = () => {
): Promise<T> => {
return Promise.race([
invoke<T>(cmd, args),
new Promise<T>((_, reject) => setTimeout(() => reject(new Error("Timeout")), timeout)),
new Promise<T>((_, reject) =>
setTimeout(() => reject(new Error("Timeout")), timeout),
),
]);
};
@@ -138,7 +140,8 @@ const UnlockPage = () => {
const checkAllMedia = useLockFn(async () => {
try {
setIsCheckingAll(true);
const result = await invokeWithTimeout<UnlockItem[]>("check_media_unlock");
const result =
await invokeWithTimeout<UnlockItem[]>("check_media_unlock");
const sortedItems = sortItemsByName(result);
setUnlockItems(sortedItems);
@@ -150,7 +153,7 @@ const UnlockPage = () => {
setIsCheckingAll(false);
} catch (err: any) {
setIsCheckingAll(false);
showNotice('error', err?.message || err?.toString() || '检测超时或失败');
showNotice("error", err?.message || err?.toString() || "检测超时或失败");
alert("检测超时或失败: " + (err?.message || err));
console.error("Failed to check media unlock:", err);
}
@@ -160,7 +163,8 @@ const UnlockPage = () => {
const checkSingleMedia = useLockFn(async (name: string) => {
try {
setLoadingItems((prev) => [...prev, name]);
const result = await invokeWithTimeout<UnlockItem[]>("check_media_unlock");
const result =
await invokeWithTimeout<UnlockItem[]>("check_media_unlock");
const targetItem = result.find((item: UnlockItem) => item.name === name);
@@ -181,7 +185,7 @@ const UnlockPage = () => {
setLoadingItems((prev) => prev.filter((item) => item !== name));
} catch (err: any) {
setLoadingItems((prev) => prev.filter((item) => item !== name));
showNotice('error', err?.message || err?.toString() || `检测${name}失败`);
showNotice("error", err?.message || err?.toString() || `检测${name}失败`);
alert("检测超时或失败: " + (err?.message || err));
console.error(`Failed to check ${name}:`, err);
}