4
4
FrontendConnectionStatusService as TheiaFrontendConnectionStatusService ,
5
5
} from '@theia/core/lib/browser/connection-status-service' ;
6
6
import type { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application' ;
7
+ import { WebSocketConnectionProvider } from '@theia/core/lib/browser/index' ;
7
8
import { StatusBarAlignment } from '@theia/core/lib/browser/status-bar/status-bar' ;
8
9
import { Disposable } from '@theia/core/lib/common/disposable' ;
9
10
import { Emitter , Event } from '@theia/core/lib/common/event' ;
@@ -16,11 +17,11 @@ import {
16
17
postConstruct ,
17
18
} from '@theia/core/shared/inversify' ;
18
19
import { NotificationManager } from '@theia/messages/lib/browser/notifications-manager' ;
20
+ import debounce from 'lodash.debounce' ;
19
21
import { ArduinoDaemon } from '../../../common/protocol' ;
20
22
import { assertUnreachable } from '../../../common/utils' ;
21
23
import { CreateFeatures } from '../../create/create-features' ;
22
24
import { NotificationCenter } from '../../notification-center' ;
23
- import debounce from 'lodash.debounce' ;
24
25
25
26
@injectable ( )
26
27
export class IsOnline implements FrontendApplicationContribution {
@@ -113,6 +114,8 @@ export class FrontendConnectionStatusService extends TheiaFrontendConnectionStat
113
114
private readonly daemonPort : DaemonPort ;
114
115
@inject ( IsOnline )
115
116
private readonly isOnline : IsOnline ;
117
+ @inject ( WebSocketConnectionProvider )
118
+ private readonly connectionProvider : WebSocketConnectionProvider ;
116
119
117
120
@postConstruct ( )
118
121
protected override async init ( ) : Promise < void > {
@@ -125,6 +128,10 @@ export class FrontendConnectionStatusService extends TheiaFrontendConnectionStat
125
128
}
126
129
127
130
protected override async performPingRequest ( ) : Promise < void > {
131
+ if ( ! this . connectionProvider [ 'socket' ] . connected ) {
132
+ this . updateStatus ( false ) ;
133
+ return ;
134
+ }
128
135
try {
129
136
await this . pingService . ping ( ) ;
130
137
this . updateStatus ( this . isOnline . online ) ;
@@ -164,6 +171,8 @@ export class ApplicationConnectionStatusContribution extends TheiaApplicationCon
164
171
private readonly notificationManager : NotificationManager ;
165
172
@inject ( CreateFeatures )
166
173
private readonly createFeatures : CreateFeatures ;
174
+ @inject ( WebSocketConnectionProvider )
175
+ private readonly connectionProvider : WebSocketConnectionProvider ;
167
176
168
177
private readonly offlineStatusDidChangeEmitter = new Emitter <
169
178
OfflineConnectionStatus | undefined
@@ -190,9 +199,10 @@ export class ApplicationConnectionStatusContribution extends TheiaApplicationCon
190
199
}
191
200
192
201
protected override handleOffline ( ) : void {
193
- const params = {
202
+ const params = < OfflineMessageParams > {
194
203
port : this . daemonPort . port ,
195
204
online : this . isOnline . online ,
205
+ backendConnected : this . connectionProvider [ 'socket' ] . connected , // https://github.com/arduino/arduino-ide/issues/2081
196
206
} ;
197
207
this . _offlineStatus = offlineConnectionStatusType ( params ) ;
198
208
const { text, tooltip } = offlineMessage ( params ) ;
@@ -248,6 +258,7 @@ export class ApplicationConnectionStatusContribution extends TheiaApplicationCon
248
258
interface OfflineMessageParams {
249
259
readonly port : string | undefined ;
250
260
readonly online : boolean ;
261
+ readonly backendConnected : boolean ;
251
262
}
252
263
interface OfflineMessage {
253
264
readonly text : string ;
@@ -272,8 +283,8 @@ export function offlineMessage(params: OfflineMessageParams): OfflineMessage {
272
283
function offlineConnectionStatusType (
273
284
params : OfflineMessageParams
274
285
) : OfflineConnectionStatus {
275
- const { port, online } = params ;
276
- if ( port && online ) {
286
+ const { port, online, backendConnected } = params ;
287
+ if ( ! backendConnected || ( port && online ) ) {
277
288
return 'backend' ;
278
289
}
279
290
if ( ! port ) {
0 commit comments