@@ -14,18 +14,16 @@ import { OpenSketch } from './open-sketch';
1414export class Sketchbook extends Examples {
1515 @inject ( WindowServiceExt )
1616 private readonly windowService : WindowServiceExt ;
17+ private _currentSketchbookPath : string | undefined ;
1718
1819 override onStart ( ) : void {
1920 this . sketchServiceClient . onSketchbookDidChange ( ( ) => this . update ( ) ) ;
2021 this . configService . onDidChangeSketchDirUri ( ( ) => this . update ( ) ) ;
2122 // If this window is changing the settings, and sketchbook location is included in the changeset,
2223 // then the users must be warned about the invalid sketches from the new sketchbook.
2324 this . settingsService . onWillChangeSoon ( async ( unsavedSettings ) => {
24- const sketchbookUriBeforeChange = this . configService
25- . tryGetSketchDirUri ( )
26- ?. toString ( ) ;
2725 // The sketchbook location is about to change.
28- if ( unsavedSettings . sketchbookPath !== sketchbookUriBeforeChange ) {
26+ if ( unsavedSettings . sketchbookPath !== this . _currentSketchbookPath ) {
2927 // Listen on both the settings and sketchbook location did change events
3028 const timeout = 5_000 ;
3129 const results = await Promise . allSettled ( [
@@ -41,6 +39,22 @@ export class Sketchbook extends Examples {
4139 }
4240 }
4341 } ) ;
42+ const maybeUpdateCurrentSketchbookPath = async (
43+ sketchDirUri : URI | undefined = this . configService . tryGetSketchDirUri ( )
44+ ) => {
45+ if ( sketchDirUri ) {
46+ const candidateSketchbookPath = await this . fileService . fsPath (
47+ sketchDirUri
48+ ) ;
49+ if ( candidateSketchbookPath !== this . _currentSketchbookPath ) {
50+ this . _currentSketchbookPath = candidateSketchbookPath ;
51+ }
52+ }
53+ } ;
54+ this . configService . onDidChangeSketchDirUri (
55+ maybeUpdateCurrentSketchbookPath
56+ ) ;
57+ maybeUpdateCurrentSketchbookPath ( ) ;
4458 }
4559
4660 override async onReady ( ) : Promise < void > {
0 commit comments