feat: Add Upgrade Dashboard Button (#784)

* feat: Add Upgrade Dashboard Button

* style: Adjust Element Positions
This commit is contained in:
Plutonium141 2024-06-26 18:18:48 +08:00 committed by GitHub
parent 7b3e68b72c
commit 32704fbaaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 38 deletions

View File

@ -28,6 +28,7 @@ export const [updatingGEODatabases, setUpdatingGEODatabases] =
createSignal(false) createSignal(false)
export const [flushingFakeIPData, setFlushingFakeIPData] = createSignal(false) export const [flushingFakeIPData, setFlushingFakeIPData] = createSignal(false)
export const [upgradingBackend, setUpgradingBackend] = createSignal(false) export const [upgradingBackend, setUpgradingBackend] = createSignal(false)
export const [upgradingUI, setUpgradingUI] = createSignal(false)
export const [restartingBackend, setRestartingBackend] = createSignal(false) export const [restartingBackend, setRestartingBackend] = createSignal(false)
export const reloadConfigFileAPI = async () => { export const reloadConfigFileAPI = async () => {
@ -77,6 +78,17 @@ export const upgradeBackendAPI = async () => {
setUpgradingBackend(false) setUpgradingBackend(false)
} }
export const upgradeUIAPI = async () => {
const request = useRequest()
setUpgradingUI(true)
try {
await request.post('upgrade/ui')
} catch {
/* empty */
}
setUpgradingUI(false)
}
export const restartBackendAPI = async () => { export const restartBackendAPI = async () => {
const request = useRequest() const request = useRequest()
setRestartingBackend(true) setRestartingBackend(true)

View File

@ -58,6 +58,7 @@ export default {
updateGEODatabases: 'Update GEO Databases', updateGEODatabases: 'Update GEO Databases',
restartCore: 'Restart Core', restartCore: 'Restart Core',
upgradeCore: 'Upgrade Core', upgradeCore: 'Upgrade Core',
upgradeUI: 'Upgrade Dashboard',
proxiesSorting: 'Proxies Sorting', proxiesSorting: 'Proxies Sorting',
orderNatural: 'Original order in config file', orderNatural: 'Original order in config file',
orderLatency_asc: 'By latency from low to high', orderLatency_asc: 'By latency from low to high',

View File

@ -60,6 +60,7 @@ export default {
updateGEODatabases: '更新 GEO 数据库', updateGEODatabases: '更新 GEO 数据库',
restartCore: '重启核心', restartCore: '重启核心',
upgradeCore: '更新核心', upgradeCore: '更新核心',
upgradeUI: '更新控制面板',
proxiesSorting: '节点排序', proxiesSorting: '节点排序',
orderNatural: '原配置文件中的排序', orderNatural: '原配置文件中的排序',
orderLatency_asc: '按延迟从低到高', orderLatency_asc: '按延迟从低到高',

View File

@ -18,6 +18,8 @@ import {
updatingGEODatabases, updatingGEODatabases,
upgradeBackendAPI, upgradeBackendAPI,
upgradingBackend, upgradingBackend,
upgradeUIAPI,
upgradingUI,
} from '~/apis' } from '~/apis'
import { Button, ConfigTitle } from '~/components' import { Button, ConfigTitle } from '~/components'
import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants' import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants'
@ -114,6 +116,16 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
const navigate = useNavigate() const navigate = useNavigate()
const portList = [ const portList = [
{
label: () => t('port', { name: 'Mixed' }),
key: 'mixed-port',
onChange: (e: Event & { target: HTMLInputElement }) =>
void updateBackendConfigAPI(
'mixed-port',
Number(e.target.value),
refetch,
),
},
{ {
label: () => t('port', { name: 'HTTP' }), label: () => t('port', { name: 'HTTP' }),
key: 'port', key: 'port',
@ -150,16 +162,6 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
refetch, refetch,
), ),
}, },
{
label: () => t('port', { name: 'Mixed' }),
key: 'mixed-port',
onChange: (e: Event & { target: HTMLInputElement }) =>
void updateBackendConfigAPI(
'mixed-port',
Number(e.target.value),
refetch,
),
},
] ]
const { form, setInitialValues, reset } = createForm< const { form, setInitialValues, reset } = createForm<
@ -327,14 +329,6 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
{t('reloadConfig')} {t('reloadConfig')}
</Button> </Button>
<Button
class="btn-secondary"
loading={updatingGEODatabases()}
onClick={updateGEODatabasesAPI}
>
{t('updateGEODatabases')}
</Button>
<Button <Button
class="btn-accent" class="btn-accent"
loading={flushingFakeIPData()} loading={flushingFakeIPData()}
@ -343,16 +337,6 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
{t('flushFakeIP')} {t('flushFakeIP')}
</Button> </Button>
<Show when={!isSingBox(backendVersion())}>
<Button
class="btn-error"
loading={upgradingBackend()}
onClick={upgradeBackendAPI}
>
{t('upgradeCore')}
</Button>
</Show>
<Button <Button
class="btn-warning" class="btn-warning"
loading={restartingBackend()} loading={restartingBackend()}
@ -361,15 +345,31 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
{t('restartCore')} {t('restartCore')}
</Button> </Button>
<Show when={!isSingBox(backendVersion())}>
<Button
class="btn-secondary"
loading={updatingGEODatabases()}
onClick={updateGEODatabasesAPI}
>
{t('updateGEODatabases')}
</Button>
<Button <Button
class="btn-info" class="btn-info"
onClick={() => { loading={upgradingUI()}
setSelectedEndpoint('') onClick={upgradeUIAPI}
navigate(ROUTES.Setup)
}}
> >
{t('switchEndpoint')} {t('upgradeUI')}
</Button> </Button>
<Button
class="btn-error"
loading={upgradingBackend()}
onClick={upgradeBackendAPI}
>
{t('upgradeCore')}
</Button>
</Show>
</div> </div>
</div> </div>
) )
@ -377,7 +377,7 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
const ConfigForXd = () => { const ConfigForXd = () => {
const [t] = useI18n() const [t] = useI18n()
const navigate = useNavigate()
const languages = [ const languages = [
{ {
label: () => t('en'), label: () => t('en'),
@ -419,6 +419,19 @@ const ConfigForXd = () => {
</For> </For>
</select> </select>
</div> </div>
<div class="flex flex-col">
<div class="py-2 text-center text-lg font-semibold">&nbsp;</div>
<Button
class="btn-info"
onClick={() => {
setSelectedEndpoint('')
navigate(ROUTES.Setup)
}}
>
{t('switchEndpoint')}
</Button>
</div>
</div> </div>
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">