@@ -23,6 +23,7 @@ import { desktopAppIcon, desktopAppLabel } from "./desktop-app-presentation.ts";
2323import { DesktopClient , type DesktopConnectionHandle } from "./desktop-client.ts" ;
2424import { desktopCredentialRequirement } from "./desktop-panel-credentials.ts" ;
2525import { desktopPanelLauncherStyles } from "./desktop-panel-launcher-styles.ts" ;
26+ import { type DesktopPanelState , renderDesktopPanelRecovery } from "./desktop-panel-state.ts" ;
2627import { desktopPanelStyles } from "./desktop-panel-styles.ts" ;
2728import { desktopSourceForEnvironment } from "./desktop-source.ts" ;
2829
@@ -39,7 +40,6 @@ const panelLayout = createDockPanelLayout({
3940 defaultHeight : 420 ,
4041 defaultWidth : 560 ,
4142} ) ;
42- type DesktopPanelState = "picker" | "credentials" | "connecting" | "connected" | "disconnected" ;
4343type DesktopAppId = WorkerDesktopAppId ;
4444type DesktopCredentials = { username ?: string ; password ?: string } ;
4545type PendingDesktopConnection = {
@@ -211,11 +211,18 @@ class OpenClawDesktopPanel extends OpenClawLitElement {
211211
212212 private async connectRequestedEnvironment ( environmentId : string ) : Promise < void > {
213213 this . returnToPicker ( ) ;
214+ this . environmentId = environmentId ;
214215 this . state = "connecting" ;
215- const inventoryLoaded = await this . refreshEnvironments ( this . operationId ) ;
216- if ( inventoryLoaded ) {
217- void this . connectEnvironment ( environmentId , false ) ;
216+ const operationId = this . operationId ;
217+ const inventoryLoaded = await this . refreshEnvironments ( operationId ) ;
218+ if ( operationId !== this . operationId ) {
219+ return ;
218220 }
221+ if ( ! inventoryLoaded ) {
222+ this . state = "inventory-error" ;
223+ return ;
224+ }
225+ void this . connectEnvironment ( environmentId , false ) ;
219226 }
220227
221228 private async connectEnvironment (
@@ -231,11 +238,11 @@ class OpenClawDesktopPanel extends OpenClawLitElement {
231238 this . clearLaunchState ( ) ;
232239 this . credentials = undefined ;
233240 this . credentialAuth = undefined ;
234- this . desktopApps = [
235- ...( this . environments . find ( ( environment ) => environment . id === environmentId ) ?. worker
236- ?. desktopApps ?? [ ] ) ,
237- ] ;
238241 }
242+ this . desktopApps = [
243+ ...( this . environments . find ( ( environment ) => environment . id === environmentId ) ?. worker
244+ ?. desktopApps ?? [ ] ) ,
245+ ] ;
239246 this . disconnectConnection ( ) ;
240247 const operationId = this . operationId ;
241248 const environment = this . environments . find ( ( candidate ) => candidate . id === environmentId ) ?? {
@@ -630,27 +637,6 @@ class OpenClawDesktopPanel extends OpenClawLitElement {
630637 ` ;
631638 }
632639
633- private renderDisconnected ( ) {
634- return html `
635- < div class ="desktop-status ">
636- < div >
637- ${ t ( "desktop.disconnected" , {
638- reason : this . disconnectedReason ?? t ( "desktop.unknownReason" ) ,
639- } ) }
640- </ div >
641- < button
642- class ="desktop-button desktop-button--primary "
643- type ="button "
644- @click =${ ( ) =>
645- this . environmentId &&
646- void this . connectEnvironment ( this . environmentId , this . controlling ) }
647- >
648- ${ t ( "desktop.reconnect" ) }
649- </ button >
650- </ div >
651- ` ;
652- }
653-
654640 private renderCredentials ( ) {
655641 const ardAccount = this . credentialAuth === "ard-account" ;
656642 return html `
@@ -712,10 +698,18 @@ class OpenClawDesktopPanel extends OpenClawLitElement {
712698 : nothing }
713699 ${ this . state === "picker"
714700 ? this . renderPicker ( )
715- : this . state === "credentials"
716- ? this . renderCredentials ( )
717- : this . state === "disconnected"
718- ? this . renderDisconnected ( )
701+ : this . state === "inventory-error" || this . state === "disconnected"
702+ ? renderDesktopPanelRecovery ( {
703+ inventoryError : this . state === "inventory-error" ,
704+ reason : this . disconnectedReason ,
705+ onRetry : ( ) =>
706+ this . environmentId &&
707+ void ( this . state === "inventory-error"
708+ ? this . connectRequestedEnvironment ( this . environmentId )
709+ : this . connectEnvironment ( this . environmentId , this . controlling ) ) ,
710+ } )
711+ : this . state === "credentials"
712+ ? this . renderCredentials ( )
719713 : this . renderConnection ( ) }
720714 </ div >
721715 </ section >
0 commit comments