Skip to content

Commit 4dc9d90

Browse files
committed
make to react properly to storage change events
1 parent 26852e0 commit 4dc9d90

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/vs/platform/actions/common/menuService.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ class PersistedMenuHideState {
4343

4444
private static readonly _key = 'menu.hiddenCommands';
4545

46-
readonly onDidChange: Event<any>;
4746
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>;
4952

5053
constructor(@IStorageService private readonly _storageService: IStorageService) {
5154
try {
@@ -55,10 +58,24 @@ class PersistedMenuHideState {
5558
this._data = Object.create(null);
5659
}
5760

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+
}));
5975
}
6076

6177
dispose() {
78+
this._onDidChange.dispose();
6279
this._disposables.dispose();
6380
}
6481

@@ -94,8 +111,13 @@ class PersistedMenuHideState {
94111
}
95112

96113
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+
}
99121
}
100122
}
101123

0 commit comments

Comments
 (0)