|
383 | 383 | uiConnectSerialBtn.style.display = 'none'; |
384 | 384 | uiDisconnectBtn.style.display = 'block'; |
385 | 385 | uiCommandLineInput.disabled = false; |
386 | | - uiCommandLineInput.focus(); |
| 386 | + |
| 387 | + if (this.currentPort instanceof SerialPort) { |
| 388 | + uiDisconnectBtn.textContent = 'Disconnect from WebSerial'; |
| 389 | + } else if (this.currentPort instanceof WebUsbSerialPort) { |
| 390 | + uiDisconnectBtn.textContent = 'Disconnect from WebUSB'; |
| 391 | + } else { |
| 392 | + uiDisconnectBtn.textContent = 'Disconnect'; |
| 393 | + } |
387 | 394 | } else { |
388 | 395 | if (serial.isWebUsbSupported()) { |
389 | 396 | uiConnectWebUsbSerialBtn.style.display = 'block'; |
|
454 | 461 | await this.currentPort.forgetDevice(); |
455 | 462 | this.currentPort = null; |
456 | 463 | } |
| 464 | + } finally { |
| 465 | + this.updateUIConnectionState(); |
457 | 466 | } |
458 | 467 | } |
459 | 468 |
|
|
474 | 483 | const savedPortInfo = JSON.parse(localStorage.getItem('webUSBSerialPort')); |
475 | 484 | if (savedPortInfo) { |
476 | 485 | for (const device of grantedDevices) { |
477 | | - if (device.device.vendorId === savedPortInfo.vendorId && device.device.productId === savedPortInfo.productId) { |
| 486 | + if (device._device.vendorId === savedPortInfo.vendorId && device._device.productId === savedPortInfo.productId) { |
478 | 487 | this.currentPort = device; |
479 | 488 | break; |
480 | 489 | } |
|
501 | 510 |
|
502 | 511 | // save the port to localStorage |
503 | 512 | const portInfo = { |
504 | | - vendorId: this.currentPort.device.vendorId, |
505 | | - productId: this.currentPort.device.productId, |
| 513 | + vendorId: this.currentPort._device.vendorId, |
| 514 | + productId: this.currentPort._device.productId, |
506 | 515 | } |
507 | 516 | localStorage.setItem('webUSBSerialPort', JSON.stringify(portInfo)); |
508 | 517 |
|
509 | 518 | this.setStatus('Connected', 'info'); |
| 519 | + uiCommandLineInput.focus(); |
510 | 520 | } catch (error) { |
511 | 521 | if (first_time_connection) { |
512 | 522 | // Forget the device if a first time connection fails |
513 | 523 | await this.currentPort.forgetDevice(); |
514 | 524 | this.currentPort = null; |
515 | 525 | } |
516 | 526 | throw error; |
| 527 | + } finally { |
| 528 | + this.updateUIConnectionState(); |
517 | 529 | } |
518 | 530 |
|
519 | 531 | this.updateUIConnectionState(); |
|
530 | 542 | this.setStatus('Reconnected', 'info'); |
531 | 543 | } catch (error) { |
532 | 544 | this.setStatus(`Reconnect failed: ${error.message}`, 'error'); |
| 545 | + } finally { |
| 546 | + this.updateUIConnectionState(); |
533 | 547 | } |
534 | 548 | } |
535 | 549 | this.updateUIConnectionState(); |
|
0 commit comments