Skip to content

Commit 8674bc5

Browse files
committed
feat: Enhance inbound creation process in XrayInboundsSection
1 parent 8d6b0a1 commit 8674bc5

1 file changed

Lines changed: 42 additions & 14 deletions

File tree

dashboard/src/features/core-editor/components/xray/xray-inbounds-section.tsx

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ import { cn } from '@/lib/utils'
4040
import {
4141
buildVlessGenerationOptionsFromInboundForm,
4242
canGenerateShadowsocksPassword,
43+
createDefaultVlessOptions,
4344
generateMldsa65Keys,
4445
generateRealityKeyPair,
4546
generateRealityShortId,
4647
generateShadowsocksPassword,
48+
generateVlessEncryption,
4749
parseVlessEncryptionMethodTokenFromString,
4850
SHADOWSOCKS_ENCRYPTION_METHODS,
4951
VLESS_ENCRYPTION_METHODS,
@@ -976,6 +978,7 @@ export function XrayInboundsSection({ headerAddPulse, headerAddEpoch }: XrayInbo
976978
const wireguardKitAllowedMigrateKeyRef = useRef<string | null>(null)
977979
const initialDraftRef = useRef<Inbound | null>(null)
978980
const initialCapturedRef = useRef(false)
981+
const beginAddInboundInFlightRef = useRef(false)
979982

980983
const inbound = useMemo(() => {
981984
if (!profile) return undefined
@@ -1287,20 +1290,45 @@ export function XrayInboundsSection({ headerAddPulse, headerAddEpoch }: XrayInbo
12871290
setBlockAddWhileDraftOpen(true)
12881291
return
12891292
}
1290-
const created = createDefaultInbound({
1291-
protocol: 'vless',
1292-
transport: 'tcp',
1293-
security: 'none',
1294-
port: randomInboundPort(profile),
1295-
clientDefaults: 'empty',
1296-
})
1297-
initialDraftRef.current = created
1298-
setDraftInbound(created)
1299-
setDialogMode('add')
1300-
setIsTagAutoGenerated(true)
1301-
setIsPortAutoGenerated(true)
1302-
setDetailOpen(true)
1303-
initialCapturedRef.current = false
1293+
if (beginAddInboundInFlightRef.current) return
1294+
beginAddInboundInFlightRef.current = true
1295+
1296+
void (async () => {
1297+
try {
1298+
let created = createDefaultInbound({
1299+
protocol: 'vless',
1300+
transport: 'tcp',
1301+
security: 'none',
1302+
port: randomInboundPort(profile),
1303+
clientDefaults: 'empty',
1304+
})
1305+
let encryptionGenerated = false
1306+
1307+
try {
1308+
// Default options use native (lightweight) encryption.
1309+
const result = await generateVlessEncryption(createDefaultVlessOptions())
1310+
created = {
1311+
...created,
1312+
encryption: result.x25519.encryption,
1313+
decryption: result.x25519.decryption,
1314+
}
1315+
encryptionGenerated = true
1316+
} catch {
1317+
// Open the dialog even if generation fails; user can generate manually.
1318+
}
1319+
1320+
initialDraftRef.current = created
1321+
setDraftInbound(created)
1322+
setDialogMode('add')
1323+
setIsTagAutoGenerated(true)
1324+
setIsPortAutoGenerated(true)
1325+
setVlessDecryptionJustGenerated(encryptionGenerated)
1326+
setDetailOpen(true)
1327+
initialCapturedRef.current = false
1328+
} finally {
1329+
beginAddInboundInFlightRef.current = false
1330+
}
1331+
})()
13041332
}, [profile, detailOpen, dialogMode, draftInbound])
13051333

13061334
useSectionHeaderAddPulseEffect(headerAddPulse, headerAddEpoch, 'inbounds', beginAddInbound)

0 commit comments

Comments
 (0)