mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-30 09:50:04 +08:00
feat(events): route all backend events through a single event bus and store
Adds src/services/bus (the only listen/emit site: one handler per contract event plus the frontend-internal test-all event) and the React context/reducer app store. Migrates the five scattered subscriptions (layout events, pending failures, proxy refresh, profile update/timer, test-all), deletes the old glue (events.ts, use-listen, use-layout-events, LoadingCacheProvider), moves run state into the store, and adds an architecture gate script wired into CI. Behavior is unchanged; the run-state query's poll/focus safety net is preserved by the store provider.
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { LanguageRounded } from '@mui/icons-material'
|
||||
import { Box, Divider, MenuItem, Menu, styled, alpha } from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { BaseLoading } from '@/components/base'
|
||||
import { useIconCache } from '@/hooks/use-icon-cache'
|
||||
import { cmdTestDelay } from '@/services/cmds'
|
||||
import delayManager from '@/services/delay'
|
||||
import { subscribeVergeEvents } from '@/services/events'
|
||||
import { showNotice } from '@/services/notice-service'
|
||||
import { useTestAllCounter } from '@/store/app-store-context'
|
||||
|
||||
import { TestBox } from './test-box'
|
||||
|
||||
@@ -52,10 +52,19 @@ export const TestItem = ({ itemData, onEdit, onDelete: removeTest }: Props) => {
|
||||
{ label: t('shared.actions.delete'), handler: onDelete },
|
||||
]
|
||||
|
||||
useEffect(
|
||||
() => subscribeVergeEvents({ 'verge://test-all': () => onDelay() }),
|
||||
[url, onDelay],
|
||||
)
|
||||
// Store bump replaces the per-item event subscription; skip the initial
|
||||
// mount value and call through a ref so url changes do not re-trigger tests.
|
||||
const testAllCounter = useTestAllCounter()
|
||||
const onDelayRef = useRef(onDelay)
|
||||
onDelayRef.current = onDelay
|
||||
const mountedRef = useRef(false)
|
||||
useEffect(() => {
|
||||
if (!mountedRef.current) {
|
||||
mountedRef.current = true
|
||||
return
|
||||
}
|
||||
void onDelayRef.current()
|
||||
}, [testAllCounter])
|
||||
|
||||
return (
|
||||
<Box>
|
||||
|
||||
Reference in New Issue
Block a user