clash-verge-rev/src/hooks/useServiceInstaller.ts
Tunglies 4f1d61a56e
Revert "fix: improve Service connection method and permissions for Windows and Unix"
This reverts commit 601e99f0b5046b50acd26afd2558c8270a85cac0.

Revert "refactor: clash-verge-rev-service-ipc (#4841)"

This reverts commit 5370bd45eda1086dae968535a159dadcecfe4de5.
2025-10-11 21:21:23 +08:00

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 };
};