Skip to content

Commit ed9fc30

Browse files
authored
Avoid duplicate action registrations (microsoft#186582)
* Avoid duplicate action registrations * Use a local variable * Fix syntax error
1 parent cf30025 commit ed9fc30

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/vs/workbench/contrib/share/browser/share.contribution.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const targetMenus = [
4747
class ShareWorkbenchContribution {
4848
private static SHARE_ENABLED_SETTING = 'workbench.experimental.share.enabled';
4949

50-
private _disposables = new DisposableStore();
50+
private _disposables: DisposableStore | undefined;
5151

5252
constructor(
5353
@IShareService private readonly shareService: IShareService,
@@ -58,16 +58,22 @@ class ShareWorkbenchContribution {
5858
}
5959
this.configurationService.onDidChangeConfiguration(e => {
6060
if (e.affectsConfiguration(ShareWorkbenchContribution.SHARE_ENABLED_SETTING)) {
61-
if (this.configurationService.getValue<boolean>(ShareWorkbenchContribution.SHARE_ENABLED_SETTING)) {
61+
const settingValue = this.configurationService.getValue<boolean>(ShareWorkbenchContribution.SHARE_ENABLED_SETTING);
62+
if (settingValue === true && this._disposables === undefined) {
6263
this.registerActions();
63-
} else {
64-
this._disposables.clear();
64+
} else if (settingValue === false && this._disposables !== undefined) {
65+
this._disposables?.clear();
66+
this._disposables = undefined;
6567
}
6668
}
6769
});
6870
}
6971

7072
private registerActions() {
73+
if (!this._disposables) {
74+
this._disposables = new DisposableStore();
75+
}
76+
7177
this._disposables.add(
7278
registerAction2(class ShareAction extends Action2 {
7379
static readonly ID = 'workbench.action.share';

0 commit comments

Comments
 (0)