mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-13 13:30:31 +08:00
This reverts commit 601e99f0b5046b50acd26afd2558c8270a85cac0. Revert "refactor: clash-verge-rev-service-ipc (#4841)" This reverts commit 5370bd45eda1086dae968535a159dadcecfe4de5.
37 lines
990 B
TypeScript
37 lines
990 B
TypeScript
import { t } from "i18next";
|
|
import { useCallback } from "react";
|
|
|
|
import { installService, restartCore } from "@/services/cmds";
|
|
import { showNotice } from "@/services/noticeService";
|
|
|
|
const executeWithErrorHandling = async (
|
|
operation: () => Promise<void>,
|
|
loadingMessage: string,
|
|
successMessage?: string,
|
|
) => {
|
|
try {
|
|
showNotice("info", t(loadingMessage));
|
|
await operation();
|
|
if (successMessage) {
|
|
showNotice("success", t(successMessage));
|
|
}
|
|
} catch (err) {
|
|
const msg = (err as Error)?.message || String(err);
|
|
showNotice("error", msg);
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
export const useServiceInstaller = () => {
|
|
const installServiceAndRestartCore = useCallback(async () => {
|
|
await executeWithErrorHandling(
|
|
() => installService(),
|
|
"Installing Service...",
|
|
"Service Installed Successfully",
|
|
);
|
|
|
|
await executeWithErrorHandling(() => restartCore(), "Restarting Core...");
|
|
}, []);
|
|
return { installServiceAndRestartCore };
|
|
};
|