Files
clash-proxy/src/hooks/useServiceUninstaller.ts
Tunglies e414b49879 Refactor imports across multiple components for consistency and clarity
- Reorganized import statements in various components to ensure consistent ordering and grouping.
- Removed unnecessary imports and added missing ones where applicable.
- Improved readability and maintainability of the codebase by standardizing import styles.
2025-09-19 00:01:04 +08:00

44 lines
1.2 KiB
TypeScript

import { t } from "i18next";
import { useCallback } from "react";
import { restartCore, stopCore, uninstallService } from "@/services/cmds";
import { showNotice } from "@/services/noticeService";
import { useSystemState } from "./use-system-state";
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 useServiceUninstaller = () => {
const { mutateRunningMode, mutateServiceOk } = useSystemState();
const uninstallServiceAndRestartCore = useCallback(async () => {
await executeWithErrorHandling(() => stopCore(), "Stopping Core...");
await executeWithErrorHandling(
() => uninstallService(),
"Uninstalling Service...",
"Service Uninstalled Successfully",
);
await executeWithErrorHandling(() => restartCore(), "Restarting Core...");
}, [mutateRunningMode, mutateServiceOk]);
return { uninstallServiceAndRestartCore };
};