refactor: unify showNotice usage
This commit is contained in:
@@ -54,7 +54,7 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
const errorMsg = await changeClashCore(core);
|
||||
|
||||
if (errorMsg) {
|
||||
showNotice("error", createRawNotice(errorMsg));
|
||||
showNotice.error(createRawNotice(errorMsg));
|
||||
setChangingCore(null);
|
||||
return;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
}, 500);
|
||||
} catch (err: any) {
|
||||
setChangingCore(null);
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,11 +75,11 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
try {
|
||||
setRestarting(true);
|
||||
await restartCore();
|
||||
showNotice("success", { i18nKey: "Clash Core Restarted" });
|
||||
showNotice.success({ i18nKey: "Clash Core Restarted" });
|
||||
setRestarting(false);
|
||||
} catch (err: any) {
|
||||
setRestarting(false);
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -88,14 +88,14 @@ export function ClashCoreViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
setUpgrading(true);
|
||||
await upgradeCore();
|
||||
setUpgrading(false);
|
||||
showNotice("success", { i18nKey: "Core Version Updated" });
|
||||
showNotice.success({ i18nKey: "Core Version Updated" });
|
||||
} catch (err: any) {
|
||||
setUpgrading(false);
|
||||
const errMsg = err.response?.data?.message || err.toString();
|
||||
const showMsg = errMsg.includes("already using latest version")
|
||||
? "Already Using Latest Core Version"
|
||||
: errMsg;
|
||||
showNotice("error", { i18nKey: showMsg, fallback: showMsg });
|
||||
showNotice.error({ i18nKey: showMsg, fallback: showMsg });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
// 如果启用了外部控制器,则保存控制器地址和密钥
|
||||
if (enableController) {
|
||||
if (!controller.trim()) {
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey:
|
||||
"components.settings.externalController.messages.addressRequired",
|
||||
});
|
||||
@@ -64,7 +64,7 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
}
|
||||
|
||||
if (!secret.trim()) {
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey:
|
||||
"components.settings.externalController.messages.secretRequired",
|
||||
});
|
||||
@@ -77,12 +77,11 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
await patchInfo({ "external-controller": "" });
|
||||
}
|
||||
|
||||
showNotice("success", { i18nKey: "Configuration saved successfully" });
|
||||
showNotice.success({ i18nKey: "Configuration saved successfully" });
|
||||
setOpen(false);
|
||||
} catch (err: any) {
|
||||
const message = err?.message || err?.toString?.();
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
message
|
||||
? createPrefixedNotice(t("Failed to save configuration"), message)
|
||||
: { i18nKey: "Failed to save configuration" },
|
||||
@@ -102,7 +101,7 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
setTimeout(() => setCopySuccess(null));
|
||||
} catch (err) {
|
||||
console.warn("[ControllerViewer] copy to clipboard failed:", err);
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "components.settings.externalController.messages.copyFailed",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
skipYamlSyncRef.current = true;
|
||||
updateValuesFromConfig(parsedYaml);
|
||||
} catch {
|
||||
showNotice("error", { i18nKey: "Invalid YAML format" });
|
||||
showNotice.error({ i18nKey: "Invalid YAML format" });
|
||||
}
|
||||
}, [yamlContent, updateValuesFromConfig]);
|
||||
|
||||
@@ -551,8 +551,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
}
|
||||
}
|
||||
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(
|
||||
`${t("DNS configuration error")}:`,
|
||||
cleanErrorMsg,
|
||||
@@ -568,9 +567,9 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
}
|
||||
|
||||
setOpen(false);
|
||||
showNotice("success", { i18nKey: "DNS settings saved" });
|
||||
showNotice.success({ i18nKey: "DNS settings saved" });
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -140,12 +140,12 @@ export const HeaderConfiguration = forwardRef<ClashHeaderConfigingRef>(
|
||||
manual: true,
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "Configuration saved successfully",
|
||||
});
|
||||
},
|
||||
onError: () => {
|
||||
showNotice("error", { i18nKey: "Failed to save configuration" });
|
||||
showNotice.error({ i18nKey: "Failed to save configuration" });
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -82,7 +82,7 @@ export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
});
|
||||
setOpen(false);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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(createRawNotice(err.message || err.toString()));
|
||||
};
|
||||
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
||||
mutateVerge({ ...verge, ...patch }, false);
|
||||
|
||||
@@ -46,7 +46,7 @@ export function LiteModeViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
});
|
||||
setOpen(false);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
});
|
||||
setOpen(false);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ const AddressDisplay = ({
|
||||
size="small"
|
||||
onClick={async () => {
|
||||
await writeText(content);
|
||||
showNotice("success", { i18nKey: "Copy Success" });
|
||||
showNotice.success({ i18nKey: "Copy Success" });
|
||||
}}
|
||||
>
|
||||
<ContentCopyRounded sx={{ fontSize: "18px" }} />
|
||||
|
||||
@@ -161,7 +161,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
]);
|
||||
}
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -277,15 +277,13 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
|
||||
const onSave = useLockFn(async () => {
|
||||
if (value.duration < 1) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
t("components.settings.sysproxy.messages.durationTooShort"),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (value.bypass && !validReg.test(value.bypass)) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
t("components.settings.sysproxy.messages.invalidBypass"),
|
||||
);
|
||||
return;
|
||||
@@ -304,8 +302,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
!ipv6Regex.test(value.proxy_host) &&
|
||||
!hostnameRegex.test(value.proxy_host)
|
||||
) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
t("components.settings.sysproxy.messages.invalidProxyHost"),
|
||||
);
|
||||
return;
|
||||
@@ -410,7 +407,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
} catch (err: any) {
|
||||
console.error("配置保存失败:", err);
|
||||
mutateVerge();
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
// setOpen(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
|
||||
await patchVerge({ theme_setting: theme });
|
||||
setOpen(false);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -80,15 +80,15 @@ export function TunViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
);
|
||||
try {
|
||||
await enhanceProfiles();
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.settings.tun.messages.applied",
|
||||
});
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
setOpen(false);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -58,16 +58,12 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
|
||||
const onUpdate = useLockFn(async () => {
|
||||
if (portableFlag) {
|
||||
showNotice(
|
||||
"error",
|
||||
t("components.settings.update.messages.portableError"),
|
||||
);
|
||||
showNotice.error(t("components.settings.update.messages.portableError"));
|
||||
return;
|
||||
}
|
||||
if (!updateInfo?.body) return;
|
||||
if (breakChangeFlag) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
t("components.settings.update.messages.breakChangeError"),
|
||||
);
|
||||
return;
|
||||
@@ -95,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(createRawNotice(err?.message || err.toString()));
|
||||
} finally {
|
||||
setUpdateState(false);
|
||||
if (progressListener) {
|
||||
|
||||
@@ -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(createRawNotice(e.message || e.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -67,12 +67,11 @@ const SettingClash = ({ onError }: Props) => {
|
||||
const onUpdateGeo = async () => {
|
||||
try {
|
||||
await updateGeo();
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("components.settings.clash.messages.geoDataUpdated"),
|
||||
);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,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(createRawNotice(err.message || err.toString()));
|
||||
await patchVerge({ enable_dns_settings: !enable }).catch(() => {});
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -47,22 +47,20 @@ const SettingVergeAdvanced = ({ onError: _ }: Props) => {
|
||||
try {
|
||||
const info = await checkUpdate();
|
||||
if (!info?.available) {
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("components.settings.verge.advanced.notifications.latestVersion"),
|
||||
);
|
||||
} else {
|
||||
updateRef.current?.open();
|
||||
}
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
};
|
||||
|
||||
const onExportDiagnosticInfo = useCallback(async () => {
|
||||
await exportDiagnosticInfo();
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("components.settings.common.notifications.copySuccess"),
|
||||
1000,
|
||||
);
|
||||
@@ -70,8 +68,7 @@ const SettingVergeAdvanced = ({ onError: _ }: Props) => {
|
||||
|
||||
const copyVersion = useCallback(() => {
|
||||
navigator.clipboard.writeText(`v${version}`).then(() => {
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("components.settings.verge.advanced.notifications.versionCopied"),
|
||||
1000,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user