@@ -209,6 +209,7 @@ export class PatchWidget extends UI.Widget.Widget {
209
209
#workspace = Workspace . Workspace . WorkspaceImpl . instance ( ) ;
210
210
#automaticFileSystem =
211
211
Persistence . AutomaticFileSystemManager . AutomaticFileSystemManager . instance ( ) . automaticFileSystem ;
212
+ #applyToDisconnectedAutomaticWorkspace = false ;
212
213
213
214
constructor ( element ?: HTMLElement , view ?: View , opts ?: {
214
215
aidaClient : Host . AidaClient . AidaClient ,
@@ -518,6 +519,7 @@ export class PatchWidget extends UI.Widget.Widget {
518
519
}
519
520
520
521
override willHide ( ) : void {
522
+ this . #applyToDisconnectedAutomaticWorkspace = false ;
521
523
if ( isAiAssistancePatchingEnabled ( ) ) {
522
524
this . #workspace. removeEventListener ( Workspace . Workspace . Events . ProjectAdded , this . #onProjectAdded, this ) ;
523
525
this . #workspace. removeEventListener ( Workspace . Workspace . Events . ProjectRemoved , this . #onProjectRemoved, this ) ;
@@ -581,8 +583,14 @@ export class PatchWidget extends UI.Widget.Widget {
581
583
this . requestUpdate ( ) ;
582
584
}
583
585
584
- #onProjectAdded( ) : void {
585
- if ( this . #project === undefined ) {
586
+ #onProjectAdded( event : Common . EventTarget . EventTargetEvent < Workspace . Workspace . Project > ) : void {
587
+ const addedProject = event . data ;
588
+ if ( this . #applyToDisconnectedAutomaticWorkspace && this . #automaticFileSystem &&
589
+ addedProject === this . #workspace. projectForFileSystemRoot ( this . #automaticFileSystem. root ) ) {
590
+ this . #applyToDisconnectedAutomaticWorkspace = false ;
591
+ this . #project = addedProject ;
592
+ void this . #applyPatchAndUpdateUI( ) ;
593
+ } else if ( this . #project === undefined ) {
586
594
this . #selectDefaultProject( ) ;
587
595
}
588
596
}
@@ -623,6 +631,10 @@ export class PatchWidget extends UI.Widget.Widget {
623
631
624
632
if ( this . #project) {
625
633
await this . #applyPatchAndUpdateUI( ) ;
634
+ } else if ( this . #automaticFileSystem) {
635
+ this . #applyToDisconnectedAutomaticWorkspace = true ;
636
+ await Persistence . AutomaticFileSystemManager . AutomaticFileSystemManager . instance ( ) . connectAutomaticFileSystem (
637
+ /* addIfMissing= */ true ) ;
626
638
} else {
627
639
this . #showSelectWorkspaceDialog( { applyPatch : true } ) ;
628
640
}
0 commit comments