refactor(notice): unify showNotice API

This commit is contained in:
Slinetrac
2025-11-02 15:56:44 +08:00
Unverified
parent 3eb8e7a066
commit 5fb67cf921
35 changed files with 450 additions and 308 deletions

View File

@@ -21,7 +21,7 @@ import { closeAllConnections, upgradeCore } from "tauri-plugin-mihomo-api";
import { BaseDialog, DialogRef } from "@/components/base";
import { useVerge } from "@/hooks/use-verge";
import { changeClashCore, restartCore } from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
const VALID_CORE = [
{ name: "Mihomo", core: "verge-mihomo", chip: "Release Version" },
@@ -54,7 +54,7 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
const errorMsg = await changeClashCore(core);
if (errorMsg) {
showNotice.error(createRawNotice(errorMsg));
showNotice.error(errorMsg);
setChangingCore(null);
return;
}
@@ -65,9 +65,9 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
mutate("getVersion");
setChangingCore(null);
}, 500);
} catch (err: any) {
} catch (err) {
setChangingCore(null);
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
}
});
@@ -77,9 +77,9 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
await restartCore();
showNotice.success({ i18nKey: "Clash Core Restarted" });
setRestarting(false);
} catch (err: any) {
} catch (err) {
setRestarting(false);
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
}
});
@@ -95,7 +95,7 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
const showMsg = errMsg.includes("already using latest version")
? "Already Using Latest Core Version"
: errMsg;
showNotice.error({ i18nKey: showMsg, fallback: showMsg });
showNotice.error(showMsg);
}
});

View File

@@ -18,7 +18,7 @@ import { useTranslation } from "react-i18next";
import { BaseDialog, DialogRef, Switch } from "@/components/base";
import { useClashInfo } from "@/hooks/use-clash";
import { useVerge } from "@/hooks/use-verge";
import { createPrefixedNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
const { t } = useTranslation();
@@ -81,12 +81,11 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
setOpen(false);
} catch (err: any) {
const message = err?.message || err?.toString?.();
showNotice.error(
message
? createPrefixedNotice(t("Failed to save configuration"), message)
: { i18nKey: "Failed to save configuration" },
4000,
);
if (message) {
showNotice.error(t("Failed to save configuration"), message, 4000);
} else {
showNotice.error("Failed to save configuration", 4000);
}
} finally {
setIsSaving(false);
}

View File

@@ -29,11 +29,7 @@ import MonacoEditor from "react-monaco-editor";
import { BaseDialog, DialogRef, Switch } from "@/components/base";
import { useClash } from "@/hooks/use-clash";
import {
createPrefixedNotice,
createRawNotice,
showNotice,
} from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import { useThemeMode } from "@/services/states";
import getSystem from "@/utils/get-system";
@@ -551,12 +547,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
}
}
showNotice.error(
createPrefixedNotice(
`${t("DNS configuration error")}:`,
cleanErrorMsg,
),
);
showNotice.error(`${t("DNS configuration error")}:`, cleanErrorMsg);
return;
}
@@ -568,8 +559,8 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
setOpen(false);
showNotice.success({ i18nKey: "DNS settings saved" });
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
} catch (err) {
showNotice.error(err);
}
});

View File

@@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
import { BaseDialog, DialogRef, Switch } from "@/components/base";
import { useVerge } from "@/hooks/use-verge";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import { HotkeyInput } from "./hotkey-input";
@@ -81,8 +81,8 @@ export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
enable_global_hotkey: enableGlobalHotkey,
});
setOpen(false);
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
} catch (err) {
showNotice.error(err);
}
});

View File

@@ -23,7 +23,7 @@ import { DEFAULT_HOVER_DELAY } from "@/components/proxy/proxy-group-navigator";
import { useVerge } from "@/hooks/use-verge";
import { useWindowDecorations } from "@/hooks/use-window";
import { copyIconFile, getAppDir } from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import getSystem from "@/utils/get-system";
import { GuardState } from "./guard-state";
@@ -104,7 +104,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
const onSwitchFormat = (_e: any, value: boolean) => value;
const onError = (err: any) => {
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
};
const onChangeData = (patch: Partial<IVergeConfig>) => {
mutateVerge({ ...verge, ...patch }, false);

View File

@@ -15,7 +15,7 @@ import { BaseDialog, DialogRef, Switch } from "@/components/base";
import { TooltipIcon } from "@/components/base/base-tooltip-icon";
import { useVerge } from "@/hooks/use-verge";
import { entry_lightweight_mode } from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
export function LiteModeViewer({ ref }: { ref?: Ref<DialogRef> }) {
const { t } = useTranslation();
@@ -45,8 +45,8 @@ export function LiteModeViewer({ ref }: { ref?: Ref<DialogRef> }) {
auto_light_weight_minutes: values.autoEnterLiteModeDelay,
});
setOpen(false);
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
} catch (err) {
showNotice.error(err);
}
});

View File

@@ -14,7 +14,7 @@ import { useTranslation } from "react-i18next";
import { BaseDialog, DialogRef, Switch } from "@/components/base";
import { TooltipIcon } from "@/components/base/base-tooltip-icon";
import { useVerge } from "@/hooks/use-verge";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation();
@@ -69,8 +69,8 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
auto_log_clean: values.autoLogClean as any,
});
setOpen(false);
} catch (err: any) {
showNotice.error(createRawNotice(err.toString()));
} catch (err) {
showNotice.error(err);
}
});

View File

@@ -36,7 +36,7 @@ import {
getSystemProxy,
patchVergeConfig,
} from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import getSystem from "@/utils/get-system";
const sleep = (ms: number) =>
@@ -160,8 +160,8 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
mutate("getAutotemProxy"),
]);
}
} catch (err: any) {
showNotice.error(createRawNotice(err.toString()));
} catch (err) {
showNotice.error(err);
}
};
@@ -404,10 +404,10 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
console.warn("代理状态更新失败:", err);
}
}, 50);
} catch (err: any) {
} catch (err) {
console.error("配置保存失败:", err);
mutateVerge();
showNotice.error(createRawNotice(err.toString()));
showNotice.error(err);
// setOpen(true);
}
});

View File

@@ -16,7 +16,7 @@ import { BaseDialog, DialogRef } from "@/components/base";
import { EditorViewer } from "@/components/profile/editor-viewer";
import { useVerge } from "@/hooks/use-verge";
import { defaultDarkTheme, defaultTheme } from "@/pages/_theme";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
const { ref } = props;
@@ -50,8 +50,8 @@ export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
try {
await patchVerge({ theme_setting: theme });
setOpen(false);
} catch (err: any) {
showNotice.error(createRawNotice(err.toString()));
} catch (err) {
showNotice.error(err);
}
});

View File

@@ -15,7 +15,7 @@ import { useTranslation } from "react-i18next";
import { BaseDialog, DialogRef, Switch } from "@/components/base";
import { useClash } from "@/hooks/use-clash";
import { enhanceProfiles } from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import getSystem from "@/utils/get-system";
import { StackModeSwitch } from "./stack-mode-switch";
@@ -80,15 +80,13 @@ export function TunViewer({ ref }: { ref?: Ref<DialogRef> }) {
);
try {
await enhanceProfiles();
showNotice.success({
i18nKey: "components.settings.tun.messages.applied",
});
showNotice.success("components.settings.tun.messages.applied");
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
}
setOpen(false);
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
}
});

View File

@@ -12,7 +12,7 @@ import useSWR from "swr";
import { BaseDialog, DialogRef } from "@/components/base";
import { useListen } from "@/hooks/use-listen";
import { portableFlag } from "@/pages/_layout";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import { useSetUpdateState, useUpdateState } from "@/services/states";
import { checkUpdateSafe as checkUpdate } from "@/services/update";
@@ -91,7 +91,7 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
await updateInfo.downloadAndInstall();
await relaunch();
} catch (err: any) {
showNotice.error(createRawNotice(err?.message || err.toString()));
showNotice.error(err);
} finally {
setUpdateState(false);
if (progressListener) {

View File

@@ -8,7 +8,7 @@ import { BaseDialog, BaseEmpty, DialogRef } from "@/components/base";
import { useClashInfo } from "@/hooks/use-clash";
import { useVerge } from "@/hooks/use-verge";
import { openWebUrl } from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import { WebUIItem } from "./web-ui-item";
@@ -92,7 +92,7 @@ export function WebUIViewer({ ref }: { ref?: Ref<DialogRef> }) {
await openWebUrl(url);
} catch (e: any) {
showNotice.error(createRawNotice(e.message || e.toString()));
showNotice.error(e);
}
});

View File

@@ -11,7 +11,7 @@ import { TooltipIcon } from "@/components/base/base-tooltip-icon";
import { useClash } from "@/hooks/use-clash";
import { useVerge } from "@/hooks/use-verge";
import { invoke_uwp_tool } from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import { useClashLog } from "@/services/states";
import getSystem from "@/utils/get-system";
@@ -71,7 +71,7 @@ const SettingClash = ({ onError }: Props) => {
t("components.settings.clash.messages.geoDataUpdated"),
);
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
}
};
@@ -88,7 +88,7 @@ const SettingClash = ({ onError }: Props) => {
} catch (err: any) {
setDnsSettingsEnabled(!enable);
localStorage.setItem("dns_settings_enabled", String(!enable));
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
await patchVerge({ enable_dns_settings: !enable }).catch(() => {});
throw err;
}

View File

@@ -13,7 +13,7 @@ import {
openDevTools,
openLogsDir,
} from "@/services/cmds";
import { createRawNotice, showNotice } from "@/services/noticeService";
import { showNotice } from "@/services/noticeService";
import { checkUpdateSafe as checkUpdate } from "@/services/update";
import { version } from "@root/package.json";
@@ -54,7 +54,7 @@ const SettingVergeAdvanced = ({ onError: _ }: Props) => {
updateRef.current?.open();
}
} catch (err: any) {
showNotice.error(createRawNotice(err.message || err.toString()));
showNotice.error(err);
}
};