feat(config): refresh backend version after core gets updated

This commit is contained in:
kunish 2024-10-12 22:37:11 +08:00
parent 1e7dcb13bc
commit 73b7e3e40a
No known key found for this signature in database
GPG Key ID: 67D3ACD788F3A7CD

View File

@ -163,9 +163,10 @@ const configFormSchema = z.object({
'mixed-port': z.number(), 'mixed-port': z.number(),
}) })
const ConfigForm: ParentComponent<{ isSingBox: Accessor<boolean> }> = ({ const ConfigForm: ParentComponent<{
isSingBox, isSingBox: Accessor<boolean>
}) => { fetchBackendVersion: () => Promise<void>
}> = ({ isSingBox, fetchBackendVersion }) => {
const [t] = useI18n() const [t] = useI18n()
const portList = [ const portList = [
@ -408,7 +409,10 @@ const ConfigForm: ParentComponent<{ isSingBox: Accessor<boolean> }> = ({
<Button <Button
class="btn-error" class="btn-error"
loading={upgradingBackend()} loading={upgradingBackend()}
onClick={upgradeBackendAPI} onClick={async () => {
await upgradeBackendAPI()
await fetchBackendVersion()
}}
> >
{t('upgradeCore')} {t('upgradeCore')}
</Button> </Button>
@ -527,9 +531,12 @@ const Versions: Component<{
const [isFrontendUpdateAvailable] = createResource(() => const [isFrontendUpdateAvailable] = createResource(() =>
isFrontendUpdateAvailableAPI(frontendVersion), isFrontendUpdateAvailableAPI(frontendVersion),
) )
const [isBackendUpdateAvailable] = createResource(() => const [isBackendUpdateAvailable, { refetch: fetchIsBackendUpdateAvailable }] =
isBackendUpdateAvailableAPI(backendVersion()), createResource(() => isBackendUpdateAvailableAPI(backendVersion()))
)
createEffect(() => {
fetchIsBackendUpdateAvailable()
}, backendVersion())
const UpdateAvailableIndicator = () => ( const UpdateAvailableIndicator = () => (
<span class="absolute -right-1 -top-1 flex h-3 w-3"> <span class="absolute -right-1 -top-1 flex h-3 w-3">
@ -571,9 +578,10 @@ export default () => {
const [t] = useI18n() const [t] = useI18n()
const frontendVersion = `v${import.meta.env.APP_VERSION}` const frontendVersion = `v${import.meta.env.APP_VERSION}`
const [backendVersion] = createResource(fetchBackendVersionAPI, { const [backendVersion, { refetch: fetchBackendVersion }] = createResource(
initialValue: '', fetchBackendVersionAPI,
}) { initialValue: '' },
)
const isSingBox = createMemo( const isSingBox = createMemo(
() => backendVersion()?.includes('sing-box') || false, () => backendVersion()?.includes('sing-box') || false,
@ -592,7 +600,12 @@ export default () => {
<ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle> <ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle>
<ConfigForm isSingBox={isSingBox} /> <ConfigForm
isSingBox={isSingBox}
fetchBackendVersion={() =>
fetchBackendVersion() as unknown as Promise<void>
}
/>
<ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle> <ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle>