diff --git a/src/pages/batchupdate/App.tsx b/src/pages/batchupdate/App.tsx index 163261fcf..3386cf849 100644 --- a/src/pages/batchupdate/App.tsx +++ b/src/pages/batchupdate/App.tsx @@ -17,8 +17,8 @@ import { } from "@App/app/service/service_worker/types"; import { dayFormat } from "@App/pkg/utils/day_format"; import { IconSync } from "@arco-design/web-react/icon"; -import { useAppContext } from "../store/AppContext"; import { SCRIPT_STATUS_ENABLE } from "@App/app/repo/scripts"; +import { subscribeMessage } from "@App/pages/store/global"; const CollapseItem = Collapse.Item; const { GridItem } = Grid; @@ -29,8 +29,6 @@ const { Text } = Typography; const pageExecute: Record void> = {}; function App() { - const { subscribeMessage } = useAppContext(); - const AUTO_CLOSE_PAGE = 8; // after 8s, auto close const getUrlParam = (key: string): string => { return (location.search?.includes(`${key}=`) ? new URLSearchParams(location.search).get(`${key}`) : "") || ""; diff --git a/src/pages/options/routes/ScriptList/hooks.tsx b/src/pages/options/routes/ScriptList/hooks.tsx index 42974e2d5..1d3024e18 100644 --- a/src/pages/options/routes/ScriptList/hooks.tsx +++ b/src/pages/options/routes/ScriptList/hooks.tsx @@ -15,7 +15,7 @@ import type { TEnableScript, TSortedScript, } from "@App/app/service/queue"; -import { useAppContext } from "@App/pages/store/AppContext"; +import { subscribeMessage } from "@App/pages/store/global"; import type { ScriptLoading } from "@App/pages/store/features/script"; import { fetchScript, @@ -49,10 +49,10 @@ import { Message } from "@arco-design/web-react"; import { cacheInstance } from "@App/app/cache"; import type { SearchType } from "@App/app/service/service_worker/types"; import { SearchFilter, type SearchFilterRequest } from "./SearchFilter"; +import { HookManager } from "@App/pkg/utils/hookManger"; export function useScriptList() { const { t } = useTranslation(); - const { subscribeMessage } = useAppContext(); const [scriptList, setScriptList] = useState([]); const [loadingList, setLoadingList] = useState(true); @@ -188,18 +188,15 @@ export function useScriptList() { }, }; - const unhooks = [ + const hookMgr = new HookManager(); + hookMgr.append( subscribeMessage("scriptRunStatus", pageApi.scriptRunStatus), subscribeMessage("installScript", pageApi.installScript), subscribeMessage("deleteScripts", pageApi.deleteScripts), subscribeMessage("enableScripts", pageApi.enableScripts), - subscribeMessage("sortedScripts", pageApi.sortedScripts), - ]; - return () => { - for (const unhook of unhooks) unhook(); - unhooks.length = 0; - }; - // eslint-disable-next-line react-hooks/exhaustive-deps + subscribeMessage("sortedScripts", pageApi.sortedScripts) + ); + return hookMgr.unhook; }, []); const updateScripts = (uuids: string[], data: Partial