@@ -63,6 +63,7 @@ const btnInfo = document.querySelector('.btn-info');
6363const btnSettings = document . querySelector ( '.btn-settings' ) ;
6464const terminalTitle = document . getElementById ( 'terminal-title' ) ;
6565const serialPlotter = document . getElementById ( 'plotter' ) ;
66+ const connectionIndicator = document . getElementById ( 'connection-indicator' ) ;
6667
6768const messageDialog = new MessageModal ( "message" ) ;
6869const connectionType = new ButtonValueDialog ( "connection-type" ) ;
@@ -122,28 +123,28 @@ function getConnectionIndicatorType() {
122123 return getLastBackend ( ) ;
123124}
124125
125- function getConnectButtonContents ( isConnected ) {
126- const action = isConnected ? "Disconnect" : "Connect" ;
126+ function getConnectButtonState ( isConnected ) {
127+ return {
128+ label : isConnected ? "Disconnect" : "Connect" ,
129+ title : isConnected ? "Disconnect" : "Connect" ,
130+ } ;
131+ }
132+
133+ function getConnectionIndicatorState ( isConnected ) {
127134 const connectionType = getConnectionIndicatorType ( ) ;
128135 const details = CONNECTION_DETAILS [ connectionType ] ;
129136
130137 if ( ! details ) {
131- return {
132- html : action ,
133- label : action ,
134- title : action ,
135- } ;
138+ return null ;
136139 }
137140
138- const status = isConnected ? "Connected via" : "Last connection" ;
139- const actionLabel = isConnected
140- ? `Disconnect ${ details . label } `
141- : `Connect using ${ details . label } ` ;
141+ const title = isConnected
142+ ? `Connected with ${ details . label } `
143+ : `Last connection: ${ details . label } ` ;
142144
143145 return {
144- html : `<span class="connection-indicator" aria-hidden="true"><i class="${ details . iconClass } "></i><span class="connection-label">${ details . label } </span></span> <span class="connect-action">${ action } </span>` ,
145- label : actionLabel ,
146- title : `${ status } : ${ details . label } ` ,
146+ iconClass : details . iconClass ,
147+ title,
147148 } ;
148149}
149150
@@ -777,11 +778,27 @@ async function debugLog(msg) {
777778}
778779
779780function updateUIConnected ( isConnected ) {
780- const buttonState = getConnectButtonContents ( isConnected ) ;
781+ const buttonState = getConnectButtonState ( isConnected ) ;
782+ const indicatorState = getConnectionIndicatorState ( isConnected ) ;
783+
784+ if ( indicatorState ) {
785+ connectionIndicator . innerHTML = `<i class="${ indicatorState . iconClass } "></i>` ;
786+ connectionIndicator . setAttribute ( "aria-label" , indicatorState . title ) ;
787+ connectionIndicator . title = indicatorState . title ;
788+ connectionIndicator . hidden = false ;
789+ connectionIndicator . classList . toggle ( "connected" , isConnected ) ;
790+ } else {
791+ connectionIndicator . replaceChildren ( ) ;
792+ connectionIndicator . removeAttribute ( "aria-label" ) ;
793+ connectionIndicator . removeAttribute ( "title" ) ;
794+ connectionIndicator . hidden = true ;
795+ connectionIndicator . classList . remove ( "connected" ) ;
796+ }
797+
781798 if ( isConnected ) {
782799 // Set to Connected State
783800 getConnectButtons ( ) . forEach ( ( element ) => {
784- element . innerHTML = buttonState . html ;
801+ element . textContent = buttonState . label ;
785802 element . setAttribute ( "aria-label" , buttonState . label ) ;
786803 element . title = buttonState . title ;
787804 element . disabled = false ;
@@ -792,7 +809,7 @@ function updateUIConnected(isConnected) {
792809 } else {
793810 // Set to Disconnected State
794811 getConnectButtons ( ) . forEach ( ( element ) => {
795- element . innerHTML = buttonState . html ;
812+ element . textContent = buttonState . label ;
796813 element . setAttribute ( "aria-label" , buttonState . label ) ;
797814 element . title = buttonState . title ;
798815 element . disabled = false ;
0 commit comments