Skip to content

Commit 5a75fd9

Browse files
committed
Optimistically try to connect to WSA when ADB is available on Windows
1 parent 25fe4f1 commit 5a75fd9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

custom-typings/adbkit.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ declare module '@devicefarmer/adbkit' {
3939
root(id: string): Promise<true>;
4040
on(type: 'error', handler: (error: Error) => void): void;
4141
reverse(id: string, remote: string, local: string): Promise<true>;
42+
connect(host: string, port?: number): Promise<void>;
4243
}
4344

4445
export function createClient(options?: {

src/interceptors/android/adb-commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ export function createAdbClient() {
2020
: 'adb'
2121
});
2222

23+
if (process.platform === 'win32') {
24+
// If ADB is connected (=if list works) then we try to connect to 58526 automatically
25+
// (but asychronously) at start up. This is the local debug port for Windows
26+
// Subsystem for Android:
27+
// https://learn.microsoft.com/en-us/windows/android/wsa/#connect-to-the-windows-subsystem-for-android-for-debugging
28+
29+
client.listDevices()
30+
.then(() => client.connect('127.0.0.1', 58526))
31+
.then(() => console.log('Connected to WSA via ADB'))
32+
.catch(() => {}); // Just best-efforts, so we ignore any failures here
33+
}
34+
2335
// We listen for errors and report them. This only happens if adbkit completely
2436
// fails to handle or listen to a connection error. We'd rather report that than crash.
2537
client.on('error', reportError);

0 commit comments

Comments
 (0)