Skip to content

Commit

Permalink
feat(adb): add getListenAddresses to AdbTcpIpCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Aug 25, 2023
1 parent 0572c68 commit 64496e2
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions packages/demo/src/pages/tcpip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -153,7 +142,7 @@ const TcpIp: NextPage = () => {
state.servicePortEnabled = !!value;
});
},
[]
[],
);

const handleServicePortChange = useCallback(
Expand All @@ -163,7 +152,7 @@ const TcpIp: NextPage = () => {
}
runInAction(() => (state.servicePort = value));
},
[]
[],
);

return (
Expand Down

0 comments on commit 64496e2

Please sign in to comment.