mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 01:39:21 +02:00
feat(adb): add getListenAddresses
to AdbTcpIpCommand
This commit is contained in:
parent
6a4e4e72c6
commit
aeff1f8818
5 changed files with 65 additions and 24 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
@ -2,6 +2,7 @@
|
|||
"cSpell.words": [
|
||||
"ADB's",
|
||||
"adbd",
|
||||
"addrs",
|
||||
"allowlist",
|
||||
"arraybuffer",
|
||||
"autorun",
|
||||
|
|
|
@ -24,10 +24,10 @@ In this mode, this library talks to a Google ADB server, which is either running
|
|||
|
||||
## Compatibility
|
||||
|
||||
| Connection | Chromium-based Browsers | Firefox | Node.js |
|
||||
| ----------------------------------------- | ------------------------------ | --------- | ----------------------------- |
|
||||
| USB cable | Supported using [WebUSB] API | No | Supported using `usb` package |
|
||||
| Wireless through [WebSocket] <sup>1</sup> | Supported | Supported | Possible using `ws` package |
|
||||
| Connection | Chromium-based Browsers | Firefox | Node.js |
|
||||
| ----------------------------------------- | -------------------------------- | --------- | ----------------------------- |
|
||||
| USB cable | Supported using [WebUSB] API | No | Supported using `usb` package |
|
||||
| Wireless through [WebSocket] <sup>1</sup> | Supported | Supported | Possible using `ws` package |
|
||||
| Wireless through TCP | Waiting for [Direct Sockets] API | No | Possible using `net` module |
|
||||
|
||||
[webusb]: https://wicg.github.io/webusb/
|
||||
|
|
|
@ -77,30 +77,19 @@ class TcpIpState {
|
|||
return;
|
||||
}
|
||||
|
||||
const serviceListenAddresses = await GLOBAL_STATE.adb.getProp(
|
||||
"service.adb.listen_addrs"
|
||||
);
|
||||
const servicePort = await GLOBAL_STATE.adb.getProp(
|
||||
"service.adb.tcp.port"
|
||||
);
|
||||
const persistPort = await GLOBAL_STATE.adb.getProp(
|
||||
"persist.adb.tcp.port"
|
||||
);
|
||||
const { serviceListenAddresses, servicePort, persistPort } =
|
||||
await GLOBAL_STATE.adb.tcpip.getListenAddresses();
|
||||
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
runInAction(() => {
|
||||
this.serviceListenAddresses =
|
||||
serviceListenAddresses !== ""
|
||||
? serviceListenAddresses.split(",")
|
||||
: undefined;
|
||||
this.serviceListenAddresses = serviceListenAddresses;
|
||||
|
||||
if (servicePort) {
|
||||
this.servicePortEnabled =
|
||||
!serviceListenAddresses && servicePort !== "0";
|
||||
this.servicePort = servicePort;
|
||||
this.servicePortEnabled = !serviceListenAddresses;
|
||||
this.servicePort = servicePort.toString();
|
||||
} else {
|
||||
this.servicePortEnabled = false;
|
||||
this.servicePort = "5555";
|
||||
|
@ -109,7 +98,7 @@ class TcpIpState {
|
|||
if (persistPort) {
|
||||
this.persistPortEnabled =
|
||||
!serviceListenAddresses && !servicePort;
|
||||
this.persistPort = persistPort;
|
||||
this.persistPort = persistPort.toString();
|
||||
} else {
|
||||
this.persistPortEnabled = false;
|
||||
this.persistPort = undefined;
|
||||
|
@ -124,7 +113,7 @@ class TcpIpState {
|
|||
|
||||
if (state.servicePortEnabled) {
|
||||
await GLOBAL_STATE.adb.tcpip.setPort(
|
||||
Number.parseInt(state.servicePort, 10)
|
||||
Number.parseInt(state.servicePort, 10),
|
||||
);
|
||||
} else {
|
||||
await GLOBAL_STATE.adb.tcpip.disable();
|
||||
|
@ -153,7 +142,7 @@ const TcpIp: NextPage = () => {
|
|||
state.servicePortEnabled = !!value;
|
||||
});
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
const handleServicePortChange = useCallback(
|
||||
|
@ -163,7 +152,7 @@ const TcpIp: NextPage = () => {
|
|||
}
|
||||
runInAction(() => (state.servicePort = value));
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
10
common/changes/@yume-chan/adb/main_2023-08-25-16-30.json
Normal file
10
common/changes/@yume-chan/adb/main_2023-08-25-16-30.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@yume-chan/adb",
|
||||
"comment": "Add `getListenAddresses` method to `AdbTcpIpCommand` class for retrieving current ADB over WiFi state",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@yume-chan/adb"
|
||||
}
|
|
@ -1,6 +1,47 @@
|
|||
import { AdbCommandBase } from "./base.js";
|
||||
|
||||
/**
|
||||
* ADB daemon checks for the following properties in the order of
|
||||
*
|
||||
* * `serviceListenAddresses` (`service.adb.listen_addrs`)
|
||||
* * `servicePort` (`service.adb.tcp.port`)
|
||||
* * `persistPort` (`persist.adb.tcp.port`)
|
||||
*
|
||||
* Once it finds a non-empty value, it will use it and ignore the rest.
|
||||
*
|
||||
* `serviceListenAddresses` and `persistPort` are fixed at build time,
|
||||
* only `servicePort` can be changed using `setPort` and `disable`.
|
||||
* This means if either `serviceListenAddresses` or `persistPort` is non-empty,
|
||||
* ADB over WiFi is always enabled.
|
||||
*/
|
||||
export interface AdbTcpIpListenAddresses {
|
||||
serviceListenAddresses: string[];
|
||||
servicePort: number | undefined;
|
||||
persistPort: number | undefined;
|
||||
}
|
||||
|
||||
export class AdbTcpIpCommand extends AdbCommandBase {
|
||||
#parsePort(value: string): number | undefined {
|
||||
if (!value || value === "0") {
|
||||
return undefined;
|
||||
}
|
||||
return Number.parseInt(value, 10);
|
||||
}
|
||||
|
||||
async getListenAddresses(): Promise<AdbTcpIpListenAddresses> {
|
||||
const serviceListenAddresses = await this.adb.getProp(
|
||||
"service.adb.listen_addrs",
|
||||
);
|
||||
const servicePort = await this.adb.getProp("service.adb.tcp.port");
|
||||
const persistPort = await this.adb.getProp("persist.adb.tcp.port");
|
||||
|
||||
return {
|
||||
serviceListenAddresses: serviceListenAddresses.split(","),
|
||||
servicePort: this.#parsePort(servicePort),
|
||||
persistPort: this.#parsePort(persistPort),
|
||||
};
|
||||
}
|
||||
|
||||
async setPort(port: number): Promise<string> {
|
||||
if (port <= 0) {
|
||||
throw new Error(`Invalid port ${port}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue