@@ -14,18 +14,16 @@ import { OpenSketch } from './open-sketch';
14
14
export class Sketchbook extends Examples {
15
15
@inject ( WindowServiceExt )
16
16
private readonly windowService : WindowServiceExt ;
17
+ private _currentSketchbookPath : string | undefined ;
17
18
18
19
override onStart ( ) : void {
19
20
this . sketchServiceClient . onSketchbookDidChange ( ( ) => this . update ( ) ) ;
20
21
this . configService . onDidChangeSketchDirUri ( ( ) => this . update ( ) ) ;
21
22
// If this window is changing the settings, and sketchbook location is included in the changeset,
22
23
// then the users must be warned about the invalid sketches from the new sketchbook.
23
24
this . settingsService . onWillChangeSoon ( async ( unsavedSettings ) => {
24
- const sketchbookUriBeforeChange = this . configService
25
- . tryGetSketchDirUri ( )
26
- ?. toString ( ) ;
27
25
// The sketchbook location is about to change.
28
- if ( unsavedSettings . sketchbookPath !== sketchbookUriBeforeChange ) {
26
+ if ( unsavedSettings . sketchbookPath !== this . _currentSketchbookPath ) {
29
27
// Listen on both the settings and sketchbook location did change events
30
28
const timeout = 5_000 ;
31
29
const results = await Promise . allSettled ( [
@@ -41,6 +39,22 @@ export class Sketchbook extends Examples {
41
39
}
42
40
}
43
41
} ) ;
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 ( ) ;
44
58
}
45
59
46
60
override async onReady ( ) : Promise < void > {
0 commit comments