Skip to content

Commit e22482d

Browse files
author
Stefania
committed
improved closeAll, added flush devices on disconnect #13
1 parent 8ed46dd commit e22482d

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/daemon.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Subject, BehaviorSubject, interval } from 'rxjs';
2-
import { takeUntil, filter, startWith } from 'rxjs/operators';
2+
import { takeUntil, filter, startWith, first } from 'rxjs/operators';
33

44
const POLLING_INTERVAL = 1500;
55

@@ -29,12 +29,11 @@ export default class Daemon {
2929
this.appMessages
3030
.subscribe(this.handleAppMessage.bind(this));
3131

32-
const devicesListSubscription = this.devicesList.subscribe((devices) => {
33-
if (devices.serial && devices.serial.length > 0) {
34-
this.closeAllPorts();
35-
devicesListSubscription.unsubscribe();
36-
}
37-
});
32+
// Close all serial ports on startup
33+
this.devicesList
34+
.pipe(filter(devices => devices.serial && devices.serial.length > 0))
35+
.pipe(first())
36+
.subscribe(this.closeAllPorts.bind(this));
3837
}
3938

4039
openChannel(cb) {
@@ -47,6 +46,10 @@ export default class Daemon {
4746
.subscribe(cb);
4847
}
4948
else {
49+
this.devicesList.next({
50+
serial: [],
51+
network: []
52+
});
5053
this.agentFound.next(false);
5154
}
5255
});

src/socket-daemon.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ export default class SocketDaemon extends Daemon {
206206
if (message.Err) {
207207
this.uploading.next({ status: this.UPLOAD_ERROR, err: message.Err });
208208
}
209+
210+
if (message.Error) {
211+
if (message.Error.indexOf('trying to close') !== -1) {
212+
// https://github.com/arduino/arduino-create-agent#openclose-ports
213+
this.serialMonitorOpened.next(false);
214+
}
215+
}
209216
}
210217

211218
handleListMessage(message) {

0 commit comments

Comments
 (0)