fix: dont confuse with incorrect version display, allow to use config values as params in real time
This commit is contained in:
parent
36bf18b02f
commit
5bb09a88bc
4 changed files with 14 additions and 15 deletions
|
|
@ -15,7 +15,7 @@ export const isServerValid = (ip: string) => {
|
|||
return !isInLocalNetwork && VALID_IP_OR_DOMAIN
|
||||
}
|
||||
|
||||
export async function fetchServerStatus (ip: string, signal?: AbortSignal) {
|
||||
export async function fetchServerStatus (ip: string, signal?: AbortSignal, versionOverride?: string) {
|
||||
if (!isServerValid(ip)) return
|
||||
|
||||
const response = await fetch(`https://api.mcstatus.io/v2/status/java/${ip}`, { signal })
|
||||
|
|
@ -25,7 +25,7 @@ export async function fetchServerStatus (ip: string, signal?: AbortSignal) {
|
|||
return {
|
||||
formattedText: data.motd?.raw ?? '',
|
||||
textNameRight: data.online ?
|
||||
`${versionClean} ${data.players?.online ?? '??'}/${data.players?.max ?? '??'}` :
|
||||
`${versionOverride ?? versionClean} ${data.players?.online ?? '??'}/${data.players?.max ?? '??'}` :
|
||||
'',
|
||||
icon: data.icon,
|
||||
offline: !data.online,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { AppConfig } from './appConfig'
|
||||
import { miscUiState } from './globalState'
|
||||
|
||||
const qsParams = new URLSearchParams(window.location?.search ?? '')
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ export const appQueryParams = new Proxy<AppQsParams>({} as AppQsParams, {
|
|||
}
|
||||
const qsParam = qsParams.get(property)
|
||||
if (qsParam) return qsParam
|
||||
return initialAppConfig.appParams?.[property]
|
||||
return miscUiState.appConfig?.appParams?.[property]
|
||||
},
|
||||
})
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ export const appQueryParamsArray = new Proxy({} as AppQsParamsArrayTransformed,
|
|||
}
|
||||
const qsParam = qsParams.getAll(property)
|
||||
if (qsParam.length) return qsParam
|
||||
return initialAppConfig.appParams?.[property] ?? []
|
||||
return miscUiState.appConfig?.appParams?.[property] ?? []
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,12 @@
|
|||
import { proxy, ref, subscribe } from 'valtio'
|
||||
import type { WorldWarp } from 'flying-squid/dist/lib/modules/warps'
|
||||
import type { OptionsGroupType } from './optionsGuiScheme'
|
||||
import { appQueryParams } from './appParams'
|
||||
import { options, disabledSettings } from './optionsStorage'
|
||||
import { AppConfig } from './appConfig'
|
||||
|
||||
// todo: refactor structure with support of hideNext=false
|
||||
|
||||
const notHideableModalsWithoutForce = new Set(['app-status'])
|
||||
|
||||
if (appQueryParams.lockConnect) {
|
||||
notHideableModalsWithoutForce.add('editServer')
|
||||
}
|
||||
export const notHideableModalsWithoutForce = new Set(['app-status'])
|
||||
|
||||
type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType: string })
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react'
|
|||
import { useUtilsEffect } from '@zardoy/react-util'
|
||||
import { useSnapshot } from 'valtio'
|
||||
import { ConnectOptions } from '../connect'
|
||||
import { activeModalStack, hideCurrentModal, miscUiState, showModal } from '../globalState'
|
||||
import { activeModalStack, hideCurrentModal, miscUiState, notHideableModalsWithoutForce, showModal } from '../globalState'
|
||||
import supportedVersions from '../supportedVersions.mjs'
|
||||
import { appQueryParams } from '../appParams'
|
||||
import { fetchServerStatus, isServerValid } from '../api/mcStatusApi'
|
||||
|
|
@ -17,6 +17,10 @@ import { useCopyKeybinding } from './simpleHooks'
|
|||
import { AuthenticatedAccount, getInitialServersList, getServerConnectionHistory, setNewServersList } from './serversStorage'
|
||||
import { appStorage, StoreServerItem } from './appStorageProvider'
|
||||
|
||||
if (appQueryParams.lockConnect) {
|
||||
notHideableModalsWithoutForce.add('editServer')
|
||||
}
|
||||
|
||||
type AdditionalDisplayData = {
|
||||
textNameRightGrayed: string
|
||||
formattedText: string
|
||||
|
|
@ -25,8 +29,6 @@ type AdditionalDisplayData = {
|
|||
offline?: boolean
|
||||
}
|
||||
|
||||
const serversListQs = appQueryParams.serversList
|
||||
|
||||
// todo move to base
|
||||
const normalizeIp = (ip: string) => ip.replace(/https?:\/\//, '').replace(/\/(:|$)/, '')
|
||||
|
||||
|
|
@ -137,7 +139,7 @@ const Inner = ({ hidden, customServersList }: { hidden?: boolean, customServersL
|
|||
offline: false
|
||||
}
|
||||
} else {
|
||||
data = await fetchServerStatus(server.ip/* , signal */) // DONT ADD SIGNAL IT WILL CRUSH JS RUNTIME
|
||||
data = await fetchServerStatus(server.ip, /* signal */undefined, server.versionOverride) // DONT ADD SIGNAL IT WILL CRUSH JS RUNTIME
|
||||
}
|
||||
if (data) {
|
||||
setAdditionalServerData(old => ({
|
||||
|
|
@ -370,6 +372,7 @@ const Inner = ({ hidden, customServersList }: { hidden?: boolean, customServersL
|
|||
}
|
||||
|
||||
export default () => {
|
||||
const serversListQs = appQueryParams.serversList
|
||||
const [customServersList, setCustomServersList] = useState<string[] | undefined>(serversListQs ? [] : undefined)
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -386,7 +389,7 @@ export default () => {
|
|||
setCustomServersList(serversListQs.split(','))
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
}, [serversListQs])
|
||||
|
||||
const modalStack = useSnapshot(activeModalStack)
|
||||
const hasServersListModal = modalStack.some(x => x.reactType === 'serversList')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue