@@ -47,6 +47,7 @@ let orderedPluginAddresses = [LOOPBACK_ADDRESS, LOOPBACK_HOST];
47
47
const CANT_FIND_AGENT_MESSAGE = 'Arduino Create Agent cannot be found' ;
48
48
49
49
let updateAttempts = 0 ;
50
+ let webSocketActionsDefined = false ;
50
51
51
52
if ( browser . name !== 'chrome' && browser . name !== 'firefox' ) {
52
53
orderedPluginAddresses = [ LOOPBACK_HOST , LOOPBACK_ADDRESS ] ;
@@ -170,11 +171,16 @@ export default class SocketDaemon extends Daemon {
170
171
this . socket = io ( address , { forceNew : true } ) ;
171
172
172
173
this . socket . on ( 'connect' , ( ) => {
173
- // On connect download windows drivers which are indispensable for detection of boards
174
- this . downloadTool ( 'windows-drivers' , 'latest' , 'arduino' ) ;
175
- this . downloadTool ( 'bossac' , '1.7.0' , 'arduino' ) ;
176
174
177
- this . initSocket ( ) ;
175
+ if ( ! webSocketActionsDefined ) {
176
+ webSocketActionsDefined = true ; // ensure calling it once
177
+
178
+ // On connect download windows drivers which are indispensable for detection of boards
179
+ this . downloadTool ( 'windows-drivers' , 'latest' , 'arduino' ) ;
180
+ this . downloadTool ( 'bossac' , '1.7.0' , 'arduino' ) ;
181
+
182
+ this . initSocket ( ) ;
183
+ }
178
184
this . channelOpen . next ( true ) ;
179
185
} ) ;
180
186
@@ -291,14 +297,14 @@ export default class SocketDaemon extends Daemon {
291
297
* @param {string } port the port name
292
298
*/
293
299
openSerialMonitor ( port , baudrate ) {
294
- if ( this . serialMonitorOpened . getValue ( ) || this . uploading . getValue ( ) . status === this . UPLOAD_IN_PROGRESS ) {
295
- return ;
296
- }
297
-
298
300
const serialPort = this . devicesList . getValue ( ) . serial . find ( p => p . Name === port ) ;
299
301
if ( ! serialPort ) {
300
302
return this . serialMonitorOpened . error ( new Error ( `Can't find board at ${ port } ` ) ) ;
301
303
}
304
+ if ( this . uploading . getValue ( ) . status === this . UPLOAD_IN_PROGRESS || serialPort . IsOpen ) {
305
+ return ;
306
+ }
307
+
302
308
this . appMessages
303
309
. pipe ( takeUntil ( this . serialMonitorOpened . pipe ( filter ( open => open ) ) ) )
304
310
. subscribe ( message => {
@@ -318,13 +324,14 @@ export default class SocketDaemon extends Daemon {
318
324
* @param {string } port the port name
319
325
*/
320
326
closeSerialMonitor ( port ) {
321
- if ( ! this . serialMonitorOpened . getValue ( ) ) {
322
- return ;
323
- }
324
327
const serialPort = this . devicesList . getValue ( ) . serial . find ( p => p . Name === port ) ;
325
328
if ( ! serialPort ) {
326
329
return this . serialMonitorOpened . error ( new Error ( `Can't find board at ${ port } ` ) ) ;
327
330
}
331
+ if ( ! serialPort . IsOpen ) {
332
+ return ;
333
+ }
334
+
328
335
this . appMessages
329
336
. pipe ( takeUntil ( this . serialMonitorOpened . pipe ( filter ( open => ! open ) ) ) )
330
337
. subscribe ( message => {
0 commit comments