refactor: unify showNotice usage
This commit is contained in:
@@ -297,7 +297,7 @@ export const HomeProfileCard = ({
|
||||
// 刷新首页数据
|
||||
refreshAll();
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()), 3000);
|
||||
showNotice.error(createRawNotice(err.message || err.toString()), 3000);
|
||||
} finally {
|
||||
setUpdating(false);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ export const ProxyTunCard: FC = () => {
|
||||
const { enable_tun_mode } = verge ?? {};
|
||||
|
||||
const handleError = (err: Error) => {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
};
|
||||
|
||||
const handleTabChange = (tab: string) => {
|
||||
|
||||
@@ -174,15 +174,15 @@ export const SystemInfoCard = () => {
|
||||
try {
|
||||
const info = await checkUpdate();
|
||||
if (!info?.available) {
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "Currently on the Latest Version",
|
||||
});
|
||||
} else {
|
||||
showNotice("info", { i18nKey: "Update Available" }, 2000);
|
||||
showNotice.info({ i18nKey: "Update Available" }, 2000);
|
||||
goToSettings();
|
||||
}
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
currData.current = value;
|
||||
onChange?.(prevData.current, currData.current);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -144,7 +144,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
}
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -152,7 +152,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
try {
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -384,14 +384,14 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
}
|
||||
|
||||
await saveProfileFile(property, nextData);
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.profile.notifications.saved",
|
||||
});
|
||||
setPrevData(nextData);
|
||||
onSave?.(prevData, nextData);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -922,8 +922,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
}
|
||||
setPrependSeq([formIns.getValues(), ...prependSeq]);
|
||||
} catch (err: any) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createRawNotice(err.message || err.toString()),
|
||||
);
|
||||
}
|
||||
@@ -951,8 +950,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
}
|
||||
setAppendSeq([...appendSeq, formIns.getValues()]);
|
||||
} catch (err: any) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createRawNotice(err.message || err.toString()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ export const ProfileItem = (props: Props) => {
|
||||
try {
|
||||
await viewProfile(itemData.uid);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err?.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export const ProfileMore = (props: Props) => {
|
||||
try {
|
||||
await viewProfile(id);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err?.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -144,8 +144,7 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
|
||||
}
|
||||
} catch {
|
||||
// 首次创建/更新失败,尝试使用自身代理
|
||||
showNotice(
|
||||
"info",
|
||||
showNotice.info(
|
||||
t("components.profile.viewer.notifications.creationRetry"),
|
||||
);
|
||||
|
||||
@@ -170,8 +169,7 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
|
||||
await patchProfile(form.uid, { option: originalOptions });
|
||||
}
|
||||
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("components.profile.viewer.notifications.creationSuccess"),
|
||||
);
|
||||
}
|
||||
@@ -187,7 +185,7 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
|
||||
onChange(isActivating);
|
||||
}, 0);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -263,13 +263,13 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
const handleSave = useLockFn(async () => {
|
||||
try {
|
||||
await saveProfileFile(property, currData);
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.profile.notifications.saved",
|
||||
});
|
||||
onSave?.(prevData, currData);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -351,8 +351,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
),
|
||||
);
|
||||
} catch (e: any) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createRawNotice(e?.message || e?.toString() || "YAML dump error"),
|
||||
);
|
||||
}
|
||||
@@ -482,13 +481,13 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
const handleSave = useLockFn(async () => {
|
||||
try {
|
||||
await saveProfileFile(property, currData);
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.profile.notifications.saved",
|
||||
});
|
||||
onSave?.(prevData, currData);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -631,8 +630,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
if (prependSeq.includes(raw)) return;
|
||||
setPrependSeq([raw, ...prependSeq]);
|
||||
} catch (err: any) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createRawNotice(err.message || err.toString()),
|
||||
);
|
||||
}
|
||||
@@ -652,8 +650,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
if (appendSeq.includes(raw)) return;
|
||||
setAppendSeq([...appendSeq, raw]);
|
||||
} catch (err: any) {
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createRawNotice(err.message || err.toString()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ export const ProviderButton = () => {
|
||||
await refreshProxy();
|
||||
await refreshProxyProviders();
|
||||
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.providers.notices.updateSuccess",
|
||||
params: { name },
|
||||
});
|
||||
} catch (err: any) {
|
||||
const message = err?.message || err?.toString?.() || String(err);
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "components.providers.notices.updateFailed",
|
||||
params: { name, message },
|
||||
});
|
||||
@@ -88,7 +88,7 @@ export const ProviderButton = () => {
|
||||
// 获取所有provider的名称
|
||||
const allProviders = Object.keys(proxyProviders || {});
|
||||
if (allProviders.length === 0) {
|
||||
showNotice("info", {
|
||||
showNotice.info({
|
||||
i18nKey: "components.providers.notices.none",
|
||||
});
|
||||
return;
|
||||
@@ -120,12 +120,12 @@ export const ProviderButton = () => {
|
||||
await refreshProxy();
|
||||
await refreshProxyProviders();
|
||||
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.providers.notices.allUpdated",
|
||||
});
|
||||
} catch (err: any) {
|
||||
const message = err?.message || err?.toString?.() || String(err);
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "components.providers.notices.genericError",
|
||||
params: { message },
|
||||
});
|
||||
|
||||
@@ -58,13 +58,13 @@ export const ProviderButton = () => {
|
||||
await refreshRules();
|
||||
await refreshRuleProviders();
|
||||
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.notices.providers.updateSuccess",
|
||||
params: { name },
|
||||
});
|
||||
} catch (err: any) {
|
||||
const message = err?.message || err?.toString?.() || String(err);
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "components.notices.providers.updateFailed",
|
||||
params: { name, message },
|
||||
});
|
||||
@@ -80,7 +80,7 @@ export const ProviderButton = () => {
|
||||
// 获取所有provider的名称
|
||||
const allProviders = Object.keys(ruleProviders || {});
|
||||
if (allProviders.length === 0) {
|
||||
showNotice("info", {
|
||||
showNotice.info({
|
||||
i18nKey: "components.notices.providers.none",
|
||||
});
|
||||
return;
|
||||
@@ -112,12 +112,12 @@ export const ProviderButton = () => {
|
||||
await refreshRules();
|
||||
await refreshRuleProviders();
|
||||
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "components.notices.providers.allUpdated",
|
||||
});
|
||||
} catch (err: any) {
|
||||
const message = err?.message || err?.toString?.() || String(err);
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "components.notices.providers.genericError",
|
||||
params: { message },
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -126,7 +126,7 @@ const ProxyControlSwitches = ({
|
||||
const { enable_tun_mode, enable_system_proxy } = verge ?? {};
|
||||
|
||||
const showErrorNotice = useCallback(
|
||||
(msg: string) => showNotice("error", { i18nKey: msg }),
|
||||
(msg: string) => showNotice.error({ i18nKey: msg }),
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -145,10 +145,7 @@ const ProxyControlSwitches = ({
|
||||
await installServiceAndRestartCore();
|
||||
await mutateSystemState();
|
||||
} catch (err) {
|
||||
showNotice(
|
||||
"error",
|
||||
createRawNotice((err as Error).message || String(err)),
|
||||
);
|
||||
showNotice.error(createRawNotice((err as Error).message || String(err)));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -160,10 +157,7 @@ const ProxyControlSwitches = ({
|
||||
await uninstallServiceAndRestartCore();
|
||||
await mutateSystemState();
|
||||
} catch (err) {
|
||||
showNotice(
|
||||
"error",
|
||||
createRawNotice((err as Error).message || String(err)),
|
||||
);
|
||||
showNotice.error(createRawNotice((err as Error).message || String(err)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export const TestItem = ({
|
||||
try {
|
||||
removeTest(uid);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ export const TestViewer = forwardRef<TestViewerRef, Props>((props, ref) => {
|
||||
setLoading(false);
|
||||
setTimeout(() => formIns.reset(), 500);
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err.message || err.toString()));
|
||||
setLoading(false);
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -67,14 +67,14 @@ export function useSystemState() {
|
||||
disablingTunMode = true;
|
||||
patchVerge({ enable_tun_mode: false })
|
||||
.then(() => {
|
||||
showNotice("info", {
|
||||
showNotice.info({
|
||||
i18nKey:
|
||||
"TUN Mode automatically disabled due to service unavailable",
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("[useVerge] 自动关闭TUN模式失败:", err);
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "Failed to disable TUN Mode automatically",
|
||||
});
|
||||
})
|
||||
|
||||
@@ -11,14 +11,14 @@ const executeWithErrorHandling = async (
|
||||
successMessage?: string,
|
||||
) => {
|
||||
try {
|
||||
showNotice("info", { i18nKey: loadingMessage });
|
||||
showNotice.info({ i18nKey: loadingMessage });
|
||||
await operation();
|
||||
if (successMessage) {
|
||||
showNotice("success", { i18nKey: successMessage });
|
||||
showNotice.success({ i18nKey: successMessage });
|
||||
}
|
||||
} catch (err) {
|
||||
const msg = (err as Error)?.message || String(err);
|
||||
showNotice("error", createRawNotice(msg));
|
||||
showNotice.error(createRawNotice(msg));
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,14 +11,14 @@ const executeWithErrorHandling = async (
|
||||
successMessage?: string,
|
||||
) => {
|
||||
try {
|
||||
showNotice("info", { i18nKey: loadingMessage });
|
||||
showNotice.info({ i18nKey: loadingMessage });
|
||||
await operation();
|
||||
if (successMessage) {
|
||||
showNotice("success", { i18nKey: successMessage });
|
||||
showNotice.success({ i18nKey: successMessage });
|
||||
}
|
||||
} catch (err) {
|
||||
const msg = (err as Error)?.message || String(err);
|
||||
showNotice("error", createRawNotice(msg));
|
||||
showNotice.error(createRawNotice(msg));
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,95 +16,83 @@ export const handleNoticeMessage = (
|
||||
const handlers: Record<string, () => void> = {
|
||||
"import_sub_url::ok": () => {
|
||||
navigate("/profile", { state: { current: msg } });
|
||||
showNotice("success", { i18nKey: "Import Subscription Successful" });
|
||||
showNotice.success({ i18nKey: "Import Subscription Successful" });
|
||||
},
|
||||
"import_sub_url::error": () => {
|
||||
navigate("/profile");
|
||||
showNotice("error", createRawNotice(msg));
|
||||
showNotice.error(createRawNotice(msg));
|
||||
},
|
||||
"set_config::error": () => showNotice("error", createRawNotice(msg)),
|
||||
"set_config::error": () => showNotice.error(createRawNotice(msg)),
|
||||
update_with_clash_proxy: () =>
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
createPrefixedNotice(t("Update with Clash proxy successfully"), msg),
|
||||
),
|
||||
update_retry_with_clash: () =>
|
||||
showNotice("info", {
|
||||
showNotice.info({
|
||||
i18nKey: "Update failed, retrying with Clash proxy...",
|
||||
}),
|
||||
update_failed_even_with_clash: () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(
|
||||
`${t("Update failed even with Clash proxy")}:`,
|
||||
msg,
|
||||
),
|
||||
),
|
||||
update_failed: () => showNotice("error", createRawNotice(msg)),
|
||||
update_failed: () => showNotice.error(createRawNotice(msg)),
|
||||
"config_validate::boot_error": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(t("Boot Config Validation Failed"), msg),
|
||||
),
|
||||
"config_validate::core_change": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(t("Core Change Config Validation Failed"), msg),
|
||||
),
|
||||
"config_validate::error": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(t("Config Validation Failed"), msg),
|
||||
),
|
||||
"config_validate::process_terminated": () =>
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "Config Validation Process Terminated",
|
||||
}),
|
||||
"config_validate::stdout_error": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(t("Config Validation Failed"), msg),
|
||||
),
|
||||
"config_validate::script_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("Script File Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("Script File Error"), msg)),
|
||||
"config_validate::script_syntax_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("Script Syntax Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("Script Syntax Error"), msg)),
|
||||
"config_validate::script_missing_main": () =>
|
||||
showNotice("error", createPrefixedNotice(t("Script Missing Main"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("Script Missing Main"), msg)),
|
||||
"config_validate::file_not_found": () =>
|
||||
showNotice("error", createPrefixedNotice(t("File Not Found"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("File Not Found"), msg)),
|
||||
"config_validate::yaml_syntax_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("YAML Syntax Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("YAML Syntax Error"), msg)),
|
||||
"config_validate::yaml_read_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("YAML Read Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("YAML Read Error"), msg)),
|
||||
"config_validate::yaml_mapping_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("YAML Mapping Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("YAML Mapping Error"), msg)),
|
||||
"config_validate::yaml_key_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("YAML Key Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("YAML Key Error"), msg)),
|
||||
"config_validate::yaml_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("YAML Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("YAML Error"), msg)),
|
||||
"config_validate::merge_syntax_error": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
createPrefixedNotice(t("Merge File Syntax Error"), msg),
|
||||
),
|
||||
showNotice.error(createPrefixedNotice(t("Merge File Syntax Error"), msg)),
|
||||
"config_validate::merge_mapping_error": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(t("Merge File Mapping Error"), msg),
|
||||
),
|
||||
"config_validate::merge_key_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("Merge File Key Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("Merge File Key Error"), msg)),
|
||||
"config_validate::merge_error": () =>
|
||||
showNotice("error", createPrefixedNotice(t("Merge File Error"), msg)),
|
||||
showNotice.error(createPrefixedNotice(t("Merge File Error"), msg)),
|
||||
"config_core::change_success": () =>
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
createPrefixedNotice(`${t("Core Changed Successfully")}:`, msg),
|
||||
),
|
||||
"config_core::change_error": () =>
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
createPrefixedNotice(`${t("Failed to Change Core")}:`, msg),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -149,8 +149,7 @@ const ProfilePage = () => {
|
||||
}
|
||||
|
||||
setActivatings((prev) => prev.filter((id) => id !== previousSwitching));
|
||||
showNotice(
|
||||
"info",
|
||||
showNotice.info(
|
||||
createPrefixedNotice(
|
||||
t("pages.profiles.notifications.switchInterrupted"),
|
||||
`${previousSwitching} → ${newProfile}`,
|
||||
@@ -198,7 +197,7 @@ const ProfilePage = () => {
|
||||
|
||||
for (const file of paths) {
|
||||
if (!file.endsWith(".yaml") && !file.endsWith(".yml")) {
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "pages.profiles.errors.onlyYaml",
|
||||
});
|
||||
continue;
|
||||
@@ -248,16 +247,14 @@ const ProfilePage = () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
await onEnhance(false);
|
||||
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
{ i18nKey: "pages.profiles.notices.forceRefreshCompleted" },
|
||||
2000,
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error("[紧急刷新] 失败:", error);
|
||||
const message = error?.message || String(error);
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
{
|
||||
i18nKey: "pages.profiles.notices.emergencyRefreshFailed",
|
||||
params: { message },
|
||||
@@ -292,7 +289,7 @@ const ProfilePage = () => {
|
||||
if (!url) return;
|
||||
// 校验url是否为http/https
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
showNotice("error", {
|
||||
showNotice.error({
|
||||
i18nKey: "pages.profiles.errors.invalidUrl",
|
||||
});
|
||||
return;
|
||||
@@ -300,7 +297,7 @@ const ProfilePage = () => {
|
||||
setLoading(true);
|
||||
|
||||
const handleImportSuccess = async (noticeKey: string) => {
|
||||
showNotice("success", { i18nKey: noticeKey });
|
||||
showNotice.success({ i18nKey: noticeKey });
|
||||
setUrl("");
|
||||
await performRobustRefresh();
|
||||
};
|
||||
@@ -312,7 +309,7 @@ const ProfilePage = () => {
|
||||
} catch (initialErr) {
|
||||
console.warn("[订阅导入] 首次导入失败:", initialErr);
|
||||
|
||||
showNotice("info", {
|
||||
showNotice.info({
|
||||
i18nKey: "pages.profiles.notifications.importRetry",
|
||||
});
|
||||
try {
|
||||
@@ -325,8 +322,7 @@ const ProfilePage = () => {
|
||||
} catch (retryErr: any) {
|
||||
// 回退导入也失败
|
||||
const retryErrmsg = retryErr?.message || retryErr.toString();
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
`${t("pages.profiles.notifications.importFail")}: ${retryErrmsg}`,
|
||||
);
|
||||
}
|
||||
@@ -374,18 +370,13 @@ const ProfilePage = () => {
|
||||
// 清除SWR缓存并重新获取
|
||||
await mutate("getProfiles", getProfiles(), { revalidate: true });
|
||||
await onEnhance(false);
|
||||
showNotice(
|
||||
"error",
|
||||
showNotice.error(
|
||||
t("pages.profiles.notifications.importNeedsRefresh"),
|
||||
3000,
|
||||
);
|
||||
} catch (finalError) {
|
||||
console.error(`[导入刷新] 最终刷新尝试失败:`, finalError);
|
||||
showNotice(
|
||||
"error",
|
||||
t("pages.profiles.notifications.importSuccess"),
|
||||
5000,
|
||||
);
|
||||
showNotice.error(t("pages.profiles.notifications.importSuccess"), 5000);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -502,8 +493,7 @@ const ProfilePage = () => {
|
||||
closeAllConnections();
|
||||
|
||||
if (notifySuccess && success) {
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("pages.profiles.notifications.profileSwitched"),
|
||||
1000,
|
||||
);
|
||||
@@ -537,11 +527,7 @@ const ProfilePage = () => {
|
||||
}
|
||||
|
||||
console.error(`[Profile] 切换失败:`, err);
|
||||
showNotice(
|
||||
"error",
|
||||
createRawNotice(err?.message || err.toString()),
|
||||
4000,
|
||||
);
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()), 4000);
|
||||
} finally {
|
||||
// 只有当前profile仍然是正在切换的profile且序列号匹配时才清理状态
|
||||
if (
|
||||
@@ -607,14 +593,13 @@ const ProfilePage = () => {
|
||||
await enhanceProfiles();
|
||||
mutateLogs();
|
||||
if (notifySuccess) {
|
||||
showNotice(
|
||||
"success",
|
||||
showNotice.success(
|
||||
t("pages.profiles.notifications.profileReactivated"),
|
||||
1000,
|
||||
);
|
||||
}
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.message || err.toString()), 3000);
|
||||
showNotice.error(createRawNotice(err.message || err.toString()), 3000);
|
||||
} finally {
|
||||
// 保留正在切换的profile,清除其他状态
|
||||
setActivatings((prev) =>
|
||||
@@ -634,7 +619,7 @@ const ProfilePage = () => {
|
||||
await onEnhance(false);
|
||||
}
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err?.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()));
|
||||
} finally {
|
||||
setActivatings([]);
|
||||
}
|
||||
@@ -750,11 +735,11 @@ const ProfilePage = () => {
|
||||
setSelectedProfiles(new Set());
|
||||
setBatchMode(false);
|
||||
|
||||
showNotice("success", {
|
||||
showNotice.success({
|
||||
i18nKey: "pages.profiles.notifications.batchDeleted",
|
||||
});
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err?.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()));
|
||||
} finally {
|
||||
setActivatings([]);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const SettingPage = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const onError = (err: any) => {
|
||||
showNotice("error", createRawNotice(err?.message || err.toString()));
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()));
|
||||
};
|
||||
|
||||
const toGithubRepo = useLockFn(() => {
|
||||
|
||||
@@ -315,19 +315,19 @@ export async function getAppDir() {
|
||||
|
||||
export async function openAppDir() {
|
||||
return invoke<void>("open_app_dir").catch((err) =>
|
||||
showNotice("error", createRawNotice(err?.message || err.toString())),
|
||||
showNotice.error(createRawNotice(err?.message || err.toString())),
|
||||
);
|
||||
}
|
||||
|
||||
export async function openCoreDir() {
|
||||
return invoke<void>("open_core_dir").catch((err) =>
|
||||
showNotice("error", createRawNotice(err?.message || err.toString())),
|
||||
showNotice.error(createRawNotice(err?.message || err.toString())),
|
||||
);
|
||||
}
|
||||
|
||||
export async function openLogsDir() {
|
||||
return invoke<void>("open_logs_dir").catch((err) =>
|
||||
showNotice("error", createRawNotice(err?.message || err.toString())),
|
||||
showNotice.error(createRawNotice(err?.message || err.toString())),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ export const openWebUrl = async (url: string) => {
|
||||
try {
|
||||
await invoke("open_web_url", { url });
|
||||
} catch (err: any) {
|
||||
showNotice("error", createRawNotice(err.toString()));
|
||||
showNotice.error(createRawNotice(err.toString()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -377,7 +377,7 @@ export async function cmdTestDelay(url: string) {
|
||||
|
||||
export async function invoke_uwp_tool() {
|
||||
return invoke<void>("invoke_uwp_tool").catch((err) =>
|
||||
showNotice("error", createRawNotice(err?.message || err.toString()), 1500),
|
||||
showNotice.error(createRawNotice(err?.message || err.toString()), 1500),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user