mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-05 02:39:26 +02:00
fix(adb): handle connection lost
This commit is contained in:
parent
6013cf9f62
commit
38a76a2e0c
4 changed files with 21 additions and 7 deletions
|
@ -182,6 +182,9 @@ function _Connect(): JSX.Element | null {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
device = await Adb.authenticate({ readable, writable }, CredentialStore, undefined);
|
device = await Adb.authenticate({ readable, writable }, CredentialStore, undefined);
|
||||||
|
device.disconnected.then(() => {
|
||||||
|
globalState.setDevice(undefined, undefined);
|
||||||
|
});
|
||||||
globalState.setDevice(selectedBackend, device);
|
globalState.setDevice(selectedBackend, device);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
device?.dispose();
|
device?.dispose();
|
||||||
|
|
|
@ -134,6 +134,8 @@ export class Adb {
|
||||||
|
|
||||||
private readonly packetDispatcher: AdbPacketDispatcher;
|
private readonly packetDispatcher: AdbPacketDispatcher;
|
||||||
|
|
||||||
|
public get disconnected() { return this.packetDispatcher.disconnected; }
|
||||||
|
|
||||||
private _protocolVersion: number | undefined;
|
private _protocolVersion: number | undefined;
|
||||||
public get protocolVersion() { return this._protocolVersion; }
|
public get protocolVersion() { return this._protocolVersion; }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AsyncOperationManager } from '@yume-chan/async';
|
import { AsyncOperationManager, PromiseResolver } from '@yume-chan/async';
|
||||||
import { AutoDisposable, EventEmitter } from '@yume-chan/event';
|
import { AutoDisposable, EventEmitter } from '@yume-chan/event';
|
||||||
import { AdbCommand, AdbPacket, calculateChecksum, type AdbPacketCore, type AdbPacketInit } from '../packet.js';
|
import { AdbCommand, AdbPacket, calculateChecksum, type AdbPacketCore, type AdbPacketInit } from '../packet.js';
|
||||||
import { AbortController, WritableStream, WritableStreamDefaultWriter, type ReadableWritablePair } from '../stream/index.js';
|
import { AbortController, WritableStream, WritableStreamDefaultWriter, type ReadableWritablePair } from '../stream/index.js';
|
||||||
|
@ -29,6 +29,9 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
||||||
public calculateChecksum = true;
|
public calculateChecksum = true;
|
||||||
public appendNullToServiceString = true;
|
public appendNullToServiceString = true;
|
||||||
|
|
||||||
|
private _disconnected = new PromiseResolver<void>();
|
||||||
|
public get disconnected() { return this._disconnected.promise; }
|
||||||
|
|
||||||
private readonly incomingSocketEvent = this.addDisposable(new EventEmitter<AdbIncomingSocketEventArgs>());
|
private readonly incomingSocketEvent = this.addDisposable(new EventEmitter<AdbIncomingSocketEventArgs>());
|
||||||
public get onIncomingSocket() { return this.incomingSocketEvent.event; }
|
public get onIncomingSocket() { return this.incomingSocketEvent.event; }
|
||||||
|
|
||||||
|
@ -69,18 +72,21 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.errorEvent.fire(e as Error);
|
this.errorEvent.fire(e as Error);
|
||||||
|
|
||||||
this.dispose();
|
|
||||||
|
|
||||||
// Throw error here will stop the pipe
|
// Throw error here will stop the pipe
|
||||||
// But won't close `readable` because of `preventCancel: true`
|
// But won't close `readable` because of `preventCancel: true`
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}), {
|
}), {
|
||||||
preventCancel: false,
|
preventCancel: false,
|
||||||
signal: this._abortController.signal,
|
signal: this._abortController.signal,
|
||||||
})
|
})
|
||||||
.catch(() => { });
|
.then(() => {
|
||||||
|
this.dispose();
|
||||||
|
}, () => {
|
||||||
|
// TODO: AdbPacketDispatcher: reject `_disconnected` when pipe errored?
|
||||||
|
this.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
this._writer = connection.writable.getWriter();
|
this._writer = connection.writable.getWriter();
|
||||||
}
|
}
|
||||||
|
@ -243,6 +249,8 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
||||||
|
|
||||||
this._writer.releaseLock();
|
this._writer.releaseLock();
|
||||||
|
|
||||||
|
this._disconnected.resolve();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,9 +202,10 @@ export class StructDeserializeStream<T extends Struct<any, any, any, any>>
|
||||||
async write(chunk) {
|
async write(chunk) {
|
||||||
await incomingStreamController.enqueue(chunk);
|
await incomingStreamController.enqueue(chunk);
|
||||||
},
|
},
|
||||||
|
abort() {
|
||||||
|
incomingStreamController.close();
|
||||||
|
},
|
||||||
close() {
|
close() {
|
||||||
// @ts-ignore
|
|
||||||
console.log('deserialization stream closed');
|
|
||||||
incomingStreamController.close();
|
incomingStreamController.close();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue