perf: ♻️ Improve wireless connection stability

This commit is contained in:
viarotel 2025-01-07 19:14:50 +08:00
parent 69fecc3bc5
commit 85be8980d4
2 changed files with 17 additions and 2 deletions

View File

@ -1,8 +1,15 @@
import ipRegex from 'ip-regex'
/**
* Determine whether it is an ipv6 address
*/
export function isIpv6(string) {
return ipRegex.v6().test(string)
}
/**
* Square brackets for IPV6 address
*/
export function ipv6Wrapper(string) {
return ipRegex.v6().test(string) ? `[${string}]` : string
return isIpv6(string) ? `[${string}]` : string
}

View File

@ -11,7 +11,7 @@ import { uniq } from 'lodash-es'
import adbConnectionMonitor from './helpers/adbConnectionMonitor/index.js'
import { streamToBase64 } from '$electron/helpers/index.js'
import { parseBatteryDump } from './helpers/battery/index.js'
import { ipv6Wrapper } from './helpers/index.js'
import { ipv6Wrapper, isIpv6 } from './helpers/index.js'
const exec = util.promisify(_exec)
@ -297,6 +297,10 @@ async function pair(host, port, code) {
}
async function connect(host, port = 5555) {
if (!isIpv6(host) && client) {
return client.connect(host, port)
}
const { stderr, stdout } = await shell(`connect ${ipv6Wrapper(host)}:${port}`)
if (stderr) {
@ -313,6 +317,10 @@ async function connect(host, port = 5555) {
}
async function disconnect(host, port = 5555) {
if (!isIpv6(host) && client) {
return client.disconnect(host, port)
}
const { stderr, stdout } = await shell(`disconnect ${ipv6Wrapper(host)}:${port}`)
if (stderr) {