@@ -43,9 +43,12 @@ class PersistedMenuHideState {
43
43
44
44
private static readonly _key = 'menu.hiddenCommands' ;
45
45
46
- readonly onDidChange : Event < any > ;
47
46
private readonly _disposables = new DisposableStore ( ) ;
48
- private readonly _data : Record < string , string [ ] | undefined > ;
47
+ private readonly _onDidChange = new Emitter < void > ( ) ;
48
+ readonly onDidChange : Event < void > = this . _onDidChange . event ;
49
+
50
+ private _ignoreChangeEvent : boolean = false ;
51
+ private _data : Record < string , string [ ] | undefined > ;
49
52
50
53
constructor ( @IStorageService private readonly _storageService : IStorageService ) {
51
54
try {
@@ -55,10 +58,24 @@ class PersistedMenuHideState {
55
58
this . _data = Object . create ( null ) ;
56
59
}
57
60
58
- this . onDidChange = Event . filter ( _storageService . onDidChangeValue , e => e . key === PersistedMenuHideState . _key , this . _disposables ) ;
61
+ this . _disposables . add ( _storageService . onDidChangeValue ( e => {
62
+ if ( e . key !== PersistedMenuHideState . _key ) {
63
+ return ;
64
+ }
65
+ if ( ! this . _ignoreChangeEvent ) {
66
+ try {
67
+ const raw = _storageService . get ( PersistedMenuHideState . _key , StorageScope . PROFILE , '{}' ) ;
68
+ this . _data = JSON . parse ( raw ) ;
69
+ } catch ( err ) {
70
+ console . log ( 'FAILED to read storage after UPDATE' , err ) ;
71
+ }
72
+ }
73
+ this . _onDidChange . fire ( ) ;
74
+ } ) ) ;
59
75
}
60
76
61
77
dispose ( ) {
78
+ this . _onDidChange . dispose ( ) ;
62
79
this . _disposables . dispose ( ) ;
63
80
}
64
81
@@ -94,8 +111,13 @@ class PersistedMenuHideState {
94
111
}
95
112
96
113
private _persist ( ) : void {
97
- const raw = JSON . stringify ( this . _data ) ;
98
- this . _storageService . store ( PersistedMenuHideState . _key , raw , StorageScope . PROFILE , StorageTarget . USER ) ;
114
+ try {
115
+ this . _ignoreChangeEvent = true ;
116
+ const raw = JSON . stringify ( this . _data ) ;
117
+ this . _storageService . store ( PersistedMenuHideState . _key , raw , StorageScope . PROFILE , StorageTarget . USER ) ;
118
+ } finally {
119
+ this . _ignoreChangeEvent = false ;
120
+ }
99
121
}
100
122
}
101
123
0 commit comments