log listener
Summary: The logs plugin opened a new log connection every time it was activated and never closed the connection. This is now changed. Once a device is connected, a log connection is opened. The logs plugin subscribes and unsubscribes to this connection. This allows the logs plugin it even access the logs from when it was not activated and ensures to only open on connection to read the logs. Logs are persisted when switching away from the plugin. Also removes the spinner from the logs plugin, as it loads much faster now. Reviewed By: jknoxville Differential Revision: D9613054 fbshipit-source-id: e37ea56c563450e7fc4e3c85a015292be1f2dbfc
This commit is contained in:
committed by
Facebook Github Bot
parent
a30e0b53e9
commit
afdc846a8b
@@ -62,6 +62,9 @@ export default class BaseDevice {
|
||||
// possible src of icon to display next to the device title
|
||||
icon: ?string;
|
||||
|
||||
logListeners: Map<Symbol, DeviceLogListener> = new Map();
|
||||
logEntries: Array<DeviceLogEntry> = [];
|
||||
|
||||
supportsOS(os: string) {
|
||||
return os.toLowerCase() === this.os.toLowerCase();
|
||||
}
|
||||
@@ -80,8 +83,22 @@ export default class BaseDevice {
|
||||
throw new Error('unimplemented');
|
||||
}
|
||||
|
||||
addLogListener(listener: DeviceLogListener) {
|
||||
throw new Error('unimplemented');
|
||||
addLogListener(callback: DeviceLogListener): Symbol {
|
||||
const id = Symbol();
|
||||
this.logListeners.set(id, callback);
|
||||
this.logEntries.map(callback);
|
||||
return id;
|
||||
}
|
||||
|
||||
notifyLogListeners(entry: DeviceLogEntry) {
|
||||
this.logEntries.push(entry);
|
||||
if (this.logListeners.size > 0) {
|
||||
this.logListeners.forEach(listener => listener(entry));
|
||||
}
|
||||
}
|
||||
|
||||
removeLogListener(id: Symbol) {
|
||||
this.logListeners.delete(id);
|
||||
}
|
||||
|
||||
spawnShell(): DeviceShell {
|
||||
|
||||
Reference in New Issue
Block a user