refactor: notification system
This commit is contained in:
@@ -25,7 +25,7 @@ import parseTraffic from "@/utils/parse-traffic";
|
||||
import { useMemo, useCallback, useState } from "react";
|
||||
import { openWebUrl, updateProfile } from "@/services/cmds";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Notice } from "@/components/base";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { EnhancedCard } from "./enhanced-card";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
|
||||
@@ -272,7 +272,7 @@ export const HomeProfileCard = ({ current, onProfileUpdated }: HomeProfileCardPr
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { refreshAll } = useAppData();
|
||||
|
||||
|
||||
// 更新当前订阅
|
||||
const [updating, setUpdating] = useState(false);
|
||||
|
||||
@@ -281,14 +281,14 @@ export const HomeProfileCard = ({ current, onProfileUpdated }: HomeProfileCardPr
|
||||
|
||||
setUpdating(true);
|
||||
try {
|
||||
await updateProfile(current.uid);
|
||||
Notice.success(t("Update subscription successfully"));
|
||||
await updateProfile(current.uid, current.option);
|
||||
showNotice('success', t("Update subscription successfully"), 1000);
|
||||
onProfileUpdated?.();
|
||||
|
||||
// 刷新首页数据
|
||||
refreshAll();
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
showNotice('error', err.message || err.toString(), 3000);
|
||||
} finally {
|
||||
setUpdating(false);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
} from "@mui/material";
|
||||
import { useState, useMemo, memo, FC } from "react";
|
||||
import ProxyControlSwitches from "@/components/shared/ProxyControlSwitches";
|
||||
import { Notice } from "@/components/base";
|
||||
import {
|
||||
ComputerRounded,
|
||||
TroubleshootRounded,
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
} from "@mui/icons-material";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { useSystemState } from "@/hooks/use-system-state";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
const LOCAL_STORAGE_TAB_KEY = "clash-verge-proxy-active-tab";
|
||||
|
||||
@@ -151,7 +151,7 @@ export const ProxyTunCard: FC = () => {
|
||||
|
||||
// 处理错误
|
||||
const handleError = (err: Error) => {
|
||||
Notice.error(err.message || err.toString(), 3000);
|
||||
showNotice('error', err.message || err.toString(), 3000);
|
||||
};
|
||||
|
||||
// 处理标签切换并保存到localStorage
|
||||
|
||||
@@ -11,13 +11,13 @@ import {
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { EnhancedCard } from "./enhanced-card";
|
||||
import useSWR from "swr";
|
||||
import { getSystemInfo, installService } from "@/services/cmds";
|
||||
import { getSystemInfo, installService, restartApp } from "@/services/cmds";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { version as appVersion } from "@root/package.json";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { check as checkUpdate } from "@tauri-apps/plugin-updater";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Notice } from "@/components/base";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { useSystemState } from "@/hooks/use-system-state";
|
||||
|
||||
export const SystemInfoCard = () => {
|
||||
@@ -117,14 +117,14 @@ export const SystemInfoCard = () => {
|
||||
// 安装系统服务
|
||||
const onInstallService = useLockFn(async () => {
|
||||
try {
|
||||
Notice.info(t("Installing Service..."), 1000);
|
||||
showNotice('info', t("Installing Service..."), 1000);
|
||||
await installService();
|
||||
Notice.success(t("Service Installed Successfully"), 2000);
|
||||
showNotice('success', t("Service Installed Successfully"), 2000);
|
||||
|
||||
await mutateRunningMode();
|
||||
await mutateRunningMode();
|
||||
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString(), 3000);
|
||||
showNotice('error', err.message || err.toString(), 3000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -140,13 +140,13 @@ export const SystemInfoCard = () => {
|
||||
try {
|
||||
const info = await checkUpdate();
|
||||
if (!info?.available) {
|
||||
Notice.success(t("Currently on the Latest Version"));
|
||||
showNotice('success', t("Currently on the Latest Version"));
|
||||
} else {
|
||||
Notice.info(t("Update Available"), 2000);
|
||||
showNotice('info', t("Update Available"), 2000);
|
||||
goToSettings();
|
||||
}
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user