Skip to content

Commit cee2f8d

Browse files
authored
Remove extra usages of Action in release notes code (microsoft#164849)
The release notes code is using `Action` just to run functions. We can get rid of all the `Action` part and just have simple functions instead
1 parent cc0341b commit cee2f8d

File tree

2 files changed

+23
-64
lines changed

2 files changed

+23
-64
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
99
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
1010
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
1111
import { MenuId, registerAction2, Action2 } from 'vs/platform/actions/common/actions';
12-
import { ProductContribution, UpdateContribution, CONTEXT_UPDATE_STATE, SwitchProductQualityContribution, RELEASE_NOTES_URL, showReleaseNotes } from 'vs/workbench/contrib/update/browser/update';
12+
import { ProductContribution, UpdateContribution, CONTEXT_UPDATE_STATE, SwitchProductQualityContribution, RELEASE_NOTES_URL, showReleaseNotesInEditor } from 'vs/workbench/contrib/update/browser/update';
1313
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
1414
import product from 'vs/platform/product/common/product';
1515
import { IUpdateService, StateType } from 'vs/platform/update/common/update';
@@ -59,7 +59,7 @@ export class ShowCurrentReleaseNotesAction extends Action2 {
5959
const openerService = accessor.get(IOpenerService);
6060

6161
try {
62-
await showReleaseNotes(instantiationService, productService.version);
62+
await showReleaseNotesInEditor(instantiationService, productService.version);
6363
} catch (err) {
6464
if (productService.releaseNotesUrl) {
6565
await openerService.open(URI.parse(productService.releaseNotesUrl));

src/vs/workbench/contrib/update/browser/update.ts

Lines changed: 21 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as nls from 'vs/nls';
77
import severity from 'vs/base/common/severity';
8-
import { Action } from 'vs/base/common/actions';
98
import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
109
import { URI } from 'vs/base/common/uri';
1110
import { IActivityService, NumberBadge, IBadge, ProgressBadge } from 'vs/workbench/services/activity/common/activity';
@@ -36,73 +35,39 @@ export const RELEASE_NOTES_URL = new RawContextKey<string>('releaseNotesUrl', ''
3635

3736
let releaseNotesManager: ReleaseNotesManager | undefined = undefined;
3837

39-
export function showReleaseNotes(instantiationService: IInstantiationService, version: string) {
38+
export function showReleaseNotesInEditor(instantiationService: IInstantiationService, version: string) {
4039
if (!releaseNotesManager) {
4140
releaseNotesManager = instantiationService.createInstance(ReleaseNotesManager);
4241
}
4342

4443
return releaseNotesManager.show(version);
4544
}
4645

47-
export class OpenLatestReleaseNotesInBrowserAction extends Action {
46+
async function openLatestReleaseNotesInBrowser(accessor: ServicesAccessor) {
47+
const openerService = accessor.get(IOpenerService);
48+
const productService = accessor.get(IProductService);
4849

49-
constructor(
50-
@IOpenerService private readonly openerService: IOpenerService,
51-
@IProductService private readonly productService: IProductService
52-
) {
53-
super('update.openLatestReleaseNotes', nls.localize('releaseNotes', "Release Notes"), undefined, true);
54-
}
55-
56-
override async run(): Promise<void> {
57-
if (this.productService.releaseNotesUrl) {
58-
const uri = URI.parse(this.productService.releaseNotesUrl);
59-
await this.openerService.open(uri);
60-
} else {
61-
throw new Error(nls.localize('update.noReleaseNotesOnline', "This version of {0} does not have release notes online", this.productService.nameLong));
62-
}
50+
if (productService.releaseNotesUrl) {
51+
const uri = URI.parse(productService.releaseNotesUrl);
52+
await openerService.open(uri);
53+
} else {
54+
throw new Error(nls.localize('update.noReleaseNotesOnline', "This version of {0} does not have release notes online", productService.nameLong));
6355
}
6456
}
6557

66-
export abstract class AbstractShowReleaseNotesAction extends Action {
67-
68-
constructor(
69-
id: string,
70-
label: string,
71-
private version: string,
72-
@IInstantiationService private readonly instantiationService: IInstantiationService
73-
) {
74-
super(id, label, undefined, true);
75-
}
76-
77-
override async run(): Promise<void> {
78-
if (!this.enabled) {
79-
return;
80-
}
81-
this.enabled = false;
82-
58+
async function showReleaseNotes(accessor: ServicesAccessor, version: string) {
59+
const instantiationService = accessor.get(IInstantiationService);
60+
try {
61+
await showReleaseNotesInEditor(instantiationService, version);
62+
} catch (err) {
8363
try {
84-
await showReleaseNotes(this.instantiationService, this.version);
85-
} catch (err) {
86-
const action = this.instantiationService.createInstance(OpenLatestReleaseNotesInBrowserAction);
87-
try {
88-
await action.run();
89-
} catch (err2) {
90-
throw new Error(`${err.message} and ${err2.message}`);
91-
}
64+
await instantiationService.invokeFunction(openLatestReleaseNotesInBrowser);
65+
} catch (err2) {
66+
throw new Error(`${err.message} and ${err2.message}`);
9267
}
9368
}
9469
}
9570

96-
export class ShowReleaseNotesAction extends AbstractShowReleaseNotesAction {
97-
98-
constructor(
99-
version: string,
100-
@IInstantiationService instantiationService: IInstantiationService
101-
) {
102-
super('update.showReleaseNotes', nls.localize('releaseNotes', "Release Notes"), version, instantiationService);
103-
}
104-
}
105-
10671
interface IVersion {
10772
major: number;
10873
minor: number;
@@ -159,7 +124,7 @@ export class ProductContribution implements IWorkbenchContribution {
159124

160125
// was there a major/minor update? if so, open release notes
161126
if (shouldShowReleaseNotes && !environmentService.skipReleaseNotes && releaseNotesUrl && lastVersion && currentVersion && isMajorMinorUpdate(lastVersion, currentVersion)) {
162-
showReleaseNotes(instantiationService, productService.version)
127+
showReleaseNotesInEditor(instantiationService, productService.version)
163128
.then(undefined, () => {
164129
notificationService.prompt(
165130
severity.Info,
@@ -317,9 +282,7 @@ export class UpdateContribution extends Disposable implements IWorkbenchContribu
317282
}, {
318283
label: nls.localize('releaseNotes', "Release Notes"),
319284
run: () => {
320-
const action = this.instantiationService.createInstance(ShowReleaseNotesAction, update.productVersion);
321-
action.run();
322-
action.dispose();
285+
this.instantiationService.invokeFunction(accessor => showReleaseNotes(accessor, update.productVersion));
323286
}
324287
}]
325288
);
@@ -343,9 +306,7 @@ export class UpdateContribution extends Disposable implements IWorkbenchContribu
343306
}, {
344307
label: nls.localize('releaseNotes', "Release Notes"),
345308
run: () => {
346-
const action = this.instantiationService.createInstance(ShowReleaseNotesAction, update.productVersion);
347-
action.run();
348-
action.dispose();
309+
this.instantiationService.invokeFunction(accessor => showReleaseNotes(accessor, update.productVersion));
349310
}
350311
}]
351312
);
@@ -370,9 +331,7 @@ export class UpdateContribution extends Disposable implements IWorkbenchContribu
370331
actions.push({
371332
label: nls.localize('releaseNotes', "Release Notes"),
372333
run: () => {
373-
const action = this.instantiationService.createInstance(ShowReleaseNotesAction, update.productVersion);
374-
action.run();
375-
action.dispose();
334+
this.instantiationService.invokeFunction(accessor => showReleaseNotes(accessor, update.productVersion));
376335
}
377336
});
378337
}

0 commit comments

Comments
 (0)