mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-06 09:02:08 +08:00
* fix: check if service installed when toggle tun mode on tray * chore: cargo fmt * fix: auto disable tun mode * docs: update UPDATELOG.md * fix: init Tun mode status * chore: update * feat: disable tun mode tray menu when tun mode is unavailable * fix: restart core when uninstall service is canceled * chore: remove check notification when toggle tun mode * chore: fix updatelog --------- Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 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 { mutateSystemState } = useSystemState();
|
|
|
|
const uninstallServiceAndRestartCore = useCallback(async () => {
|
|
try {
|
|
await executeWithErrorHandling(() => stopCore(), "Stopping Core...");
|
|
await executeWithErrorHandling(
|
|
() => uninstallService(),
|
|
"Uninstalling Service...",
|
|
"Service Uninstalled Successfully",
|
|
);
|
|
} catch (ignore) {
|
|
} finally {
|
|
await executeWithErrorHandling(
|
|
() => restartCore(),
|
|
"Restarting Core...",
|
|
"Clash Core Restarted",
|
|
);
|
|
await mutateSystemState();
|
|
}
|
|
}, [mutateSystemState]);
|
|
|
|
return { uninstallServiceAndRestartCore };
|
|
};
|