@@ -133,21 +133,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
133
133
134
134
@inject ( LabelProvider )
135
135
protected readonly labelProvider : LabelProvider ;
136
-
136
+
137
137
@inject ( QuickOpenService )
138
138
protected readonly quickOpenService : QuickOpenService ;
139
139
140
+ @inject ( WorkspaceService )
141
+ protected readonly workspaceService : WorkspaceService ;
142
+
140
143
protected boardsToolbarItem : BoardsToolBarItem | null ;
141
144
protected wsSketchCount : number = 0 ;
142
145
143
- constructor ( @inject ( WorkspaceService ) protected readonly workspaceService : WorkspaceService ) {
144
- this . workspaceService . onWorkspaceChanged ( ( ) => {
145
- if ( this . workspaceService . workspace ) {
146
- this . registerSketchesInMenu ( this . menuRegistry ) ;
147
- }
148
- } )
149
- }
150
-
151
146
@postConstruct ( )
152
147
protected async init ( ) : Promise < void > {
153
148
// This is a hack. Otherwise, the backend services won't bind.
@@ -161,6 +156,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
161
156
}
162
157
this . boardsServiceClient . onBoardsConfigChanged ( updateStatusBar ) ;
163
158
updateStatusBar ( this . boardsServiceClient . boardsConfig ) ;
159
+
160
+ this . registerSketchesInMenu ( this . menuRegistry ) ;
164
161
}
165
162
166
163
registerToolbarItems ( registry : TabBarToolbarRegistry ) : void {
@@ -453,21 +450,37 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
453
450
}
454
451
455
452
protected async getWorkspaceSketches ( ) : Promise < Sketch [ ] > {
456
- const sketches = this . sketches . getSketches ( this . workspaceService . workspace ) ;
453
+
454
+ let sketches : Sketch [ ] = [ ] ;
455
+ const userHome = await this . fileSystem . getCurrentUserHome ( ) ;
456
+ console . log ( 'userHome' , userHome ) ;
457
+ if ( ! ! userHome ) {
458
+ // TODO: get this from the backend
459
+ const result = new URI ( userHome . uri ) . resolve ( 'Arduino-PoC' ) . resolve ( 'Sketches' ) . toString ( ) ;
460
+ const stat = await this . fileSystem . getFileStat ( result ) ;
461
+ if ( ! ! stat ) {
462
+ sketches = await this . sketches . getSketches ( stat ) ;
463
+ }
464
+ }
457
465
return sketches ;
458
466
}
459
467
460
468
protected async openSketchFilesInNewWindow ( uri : string ) {
461
469
const url = new URL ( window . location . href ) ;
462
470
const currentSketch = url . searchParams . get ( 'sketch' ) ;
463
471
// Nothing to do if we want to open the same sketch which is already opened.
464
- if ( ! ! currentSketch && new URI ( currentSketch ) . toString ( ) === new URI ( uri ) . toString ( ) ) {
465
- this . messageService . info ( `The '${ this . labelProvider . getLongName ( new URI ( uri ) ) } ' is already opened.` ) ;
472
+ const sketchUri = new URI ( uri ) ;
473
+ if ( ! ! currentSketch && new URI ( currentSketch ) . toString ( ) === sketchUri . toString ( ) ) {
474
+ this . messageService . info ( `The '${ this . labelProvider . getLongName ( sketchUri ) } ' is already opened.` ) ;
466
475
// NOOP.
467
476
return ;
468
477
}
469
478
// Preserve the current window if the `sketch` is not in the `searchParams`.
470
479
url . searchParams . set ( 'sketch' , uri ) ;
480
+ const hash = await this . fileSystem . getFsPath ( sketchUri . toString ( ) ) ;
481
+ if ( hash ) {
482
+ url . hash = hash ;
483
+ }
471
484
if ( ! currentSketch ) {
472
485
setTimeout ( ( ) => window . location . href = url . toString ( ) , 100 ) ;
473
486
return ;
0 commit comments