Skip to content

Commit

Permalink
fix: use AUTO mode for port detection if dedicated port is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
berkon committed Jul 1, 2024
1 parent 9fe4613 commit 79c1ef8
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,17 @@ function connectPort ( portIdentifier ) {
return reject ( err )
})
} else if ( typeof portIdentifier === 'string') {
// Check if the port selected in an older session still exists
log.info ( `Trying to find dedicated port '${COM_PORT}'`)
let foundPortIndex = globalPorts.findIndex( port => port.path === COM_PORT )

// If not set mode to 'AUTO'
if ( foundPortIndex === -1 ) {
log.info ( `Dedicated port is not available anymore. Using 'AUTO' mode for detection!`)
portIdentifier = 'AUTO'
ipcRenderer.send ('SET_PORT', { portPath : 'AUTO' });
}

if ( portIdentifier === 'AUTO' ) { // Automatic port selection
log.info ( `Auto-detecting port ...`)

Expand All @@ -1165,17 +1176,12 @@ function connectPort ( portIdentifier ) {
})
} else { // Select port by port name string
log.info ( `Connecting to dedicated port '${COM_PORT}'`)

for ( const [index, port] of globalPorts.entries() ) {
if ( port.path === COM_PORT) {
tryPort(index).then ( () => {
portOpenCb()
return resolve()
}).catch ( err => {
return reject (err)
})
}
}
tryPort(foundPortIndex).then ( () => {
portOpenCb()
return resolve()
}).catch ( err => {
return reject (err)
})
}
}
})
Expand Down

0 comments on commit 79c1ef8

Please sign in to comment.