Skip to content

Commit

Permalink
fix(regression): ip qs param was ignored
Browse files Browse the repository at this point in the history
fix: add local (gitignored) config that is merged into single config after the build
  • Loading branch information
zardoy committed Jan 9, 2025
1 parent 36747e6 commit 87b795b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ out
generated
storybook-static
server-jar
config.local.json

src/react/npmReactComponents.ts
6 changes: 5 additions & 1 deletion rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ const appConfig = defineConfig({
fs.copyFileSync('./assets/release.json', './dist/release.json')
}
const configJson = JSON.parse(fs.readFileSync('./config.json', 'utf8'))
let configLocalJson = {}
try {
configLocalJson = JSON.parse(fs.readFileSync('./config.local.json', 'utf8'))
} catch (err) {}
if (dev) {
configJson.defaultProxy = ':8080'
}
fs.writeFileSync('./dist/config.json', JSON.stringify(configJson), 'utf8')
fs.writeFileSync('./dist/config.json', JSON.stringify({ ...configJson, ...configLocalJson }), 'utf8')
// childProcess.execSync('./scripts/prepareSounds.mjs', { stdio: 'inherit' })
// childProcess.execSync('tsx ./scripts/genMcDataTypes.ts', { stdio: 'inherit' })
// childProcess.execSync('tsx ./scripts/genPixelartTypes.ts', { stdio: 'inherit' })
Expand Down
3 changes: 3 additions & 0 deletions src/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export type AppConfig = {
peerJsServerFallback?: string
promoteServers?: Array<{ ip, description, version? }>
mapsProvider?: string

defaultSettings?: Record<string, any>
allowAutoConnect?: boolean
}

export const miscUiState = proxy({
Expand Down
13 changes: 10 additions & 3 deletions src/react/AddServerOrConnect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import Screen from './Screen'
import Input from './Input'
import Button from './Button'
Expand Down Expand Up @@ -26,11 +26,12 @@ interface Props {
accounts?: string[]
authenticatedAccounts?: number
versions?: string[]
allowAutoConnect?: boolean
}

const ELEMENTS_WIDTH = 190

export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQs, onQsConnect, placeholders, accounts, versions, authenticatedAccounts }: Props) => {
export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQs, onQsConnect, placeholders, accounts, versions, allowAutoConnect }: Props) => {
const qsParams = parseQs ? new URLSearchParams(window.location.search) : undefined
const qsParamName = qsParams?.get('name')
const qsParamIp = qsParams?.get('ip')
Expand All @@ -40,7 +41,7 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
const qsParamLockConnect = qsParams?.get('lockConnect')

const qsIpParts = qsParamIp?.split(':')
const ipParts = initialData?.ip.split(':')
const ipParts = initialData?.ip ? initialData?.ip.split(':') : undefined

const [serverName, setServerName] = React.useState(initialData?.name ?? qsParamName ?? '')
const [serverIp, setServerIp] = React.useState(ipParts?.[0] ?? qsIpParts?.[0] ?? '')
Expand Down Expand Up @@ -69,6 +70,12 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
authenticatedAccountOverride,
}

useEffect(() => {
if (qsParams?.get('autoConnect') === 'true' && qsParams?.get('ip') && allowAutoConnect) {
onQsConnect?.(commonUseOptions)
}
}, [])

return <Screen title={qsParamIp ? 'Connect to Server' : title} backdrop>
<form
style={{
Expand Down
1 change: 1 addition & 0 deletions src/react/ServersListProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const Inner = ({ hidden, customServersList }: { hidden?: boolean, customServersL
})

const editModalJsx = isEditScreenModal ? <AddServerOrConnect
allowAutoConnect={miscUiState.appConfig?.allowAutoConnect}
placeholders={{
proxyOverride: selectedProxy,
usernameOverride: defaultUsername,
Expand Down

0 comments on commit 87b795b

Please sign in to comment.