From 73b7e3e40a4a8ad18f5fece8260217ddb4bcfddb Mon Sep 17 00:00:00 2001 From: kunish Date: Sat, 12 Oct 2024 22:37:11 +0800 Subject: [PATCH] feat(config): refresh backend version after core gets updated --- src/pages/Config.tsx | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 2ce09f2..5883d62 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -163,9 +163,10 @@ const configFormSchema = z.object({ 'mixed-port': z.number(), }) -const ConfigForm: ParentComponent<{ isSingBox: Accessor }> = ({ - isSingBox, -}) => { +const ConfigForm: ParentComponent<{ + isSingBox: Accessor + fetchBackendVersion: () => Promise +}> = ({ isSingBox, fetchBackendVersion }) => { const [t] = useI18n() const portList = [ @@ -408,7 +409,10 @@ const ConfigForm: ParentComponent<{ isSingBox: Accessor }> = ({ @@ -527,9 +531,12 @@ const Versions: Component<{ const [isFrontendUpdateAvailable] = createResource(() => isFrontendUpdateAvailableAPI(frontendVersion), ) - const [isBackendUpdateAvailable] = createResource(() => - isBackendUpdateAvailableAPI(backendVersion()), - ) + const [isBackendUpdateAvailable, { refetch: fetchIsBackendUpdateAvailable }] = + createResource(() => isBackendUpdateAvailableAPI(backendVersion())) + + createEffect(() => { + fetchIsBackendUpdateAvailable() + }, backendVersion()) const UpdateAvailableIndicator = () => ( @@ -571,9 +578,10 @@ export default () => { const [t] = useI18n() const frontendVersion = `v${import.meta.env.APP_VERSION}` - const [backendVersion] = createResource(fetchBackendVersionAPI, { - initialValue: '', - }) + const [backendVersion, { refetch: fetchBackendVersion }] = createResource( + fetchBackendVersionAPI, + { initialValue: '' }, + ) const isSingBox = createMemo( () => backendVersion()?.includes('sing-box') || false, @@ -592,7 +600,12 @@ export default () => { {t('coreConfig')} - + + fetchBackendVersion() as unknown as Promise + } + /> {t('xdConfig')}