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(),
})
const ConfigForm: ParentComponent<{ isSingBox: Accessor<boolean> }> = ({
isSingBox,
}) => {
const ConfigForm: ParentComponent<{
isSingBox: Accessor<boolean>
fetchBackendVersion: () => Promise<void>
}> = ({ isSingBox, fetchBackendVersion }) => {
const [t] = useI18n()
const portList = [
@ -408,7 +409,10 @@ const ConfigForm: ParentComponent<{ isSingBox: Accessor<boolean> }> = ({
<Button
class="btn-error"
loading={upgradingBackend()}
onClick={upgradeBackendAPI}
onClick={async () => {
await upgradeBackendAPI()
await fetchBackendVersion()
}}
>
{t('upgradeCore')}
</Button>
@ -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 = () => (
<span class="absolute -right-1 -top-1 flex h-3 w-3">
@ -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 () => {
<ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle>
<ConfigForm isSingBox={isSingBox} />
<ConfigForm
isSingBox={isSingBox}
fetchBackendVersion={() =>
fetchBackendVersion() as unknown as Promise<void>
}
/>
<ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle>