Skip to content

Commit 145255c

Browse files
committed
LightUpdateContribution
1 parent fb968f3 commit 145255c

2 files changed

Lines changed: 58 additions & 54 deletions

File tree

src/vs/workbench/parts/update/electron-browser/update.contribution.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1919
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
2020
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
2121
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
22-
import { ShowCurrentReleaseNotesAction, UpdateContribution, UpdateContribution2 } from './update';
22+
import { ShowCurrentReleaseNotesAction, ProductContribution, UpdateContribution, LightUpdateContribution } from './update';
2323

2424
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
25-
.registerWorkbenchContribution(UpdateContribution);
25+
.registerWorkbenchContribution(ProductContribution);
26+
27+
if (isMacintosh) {
28+
Registry.as<IGlobalActivityRegistry>(GlobalActivityExtensions)
29+
.registerActivity(LightUpdateContribution);
30+
} else {
31+
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
32+
.registerWorkbenchContribution(UpdateContribution);
33+
}
2634

2735
// Editor
2836
const editorDescriptor = new EditorDescriptor(
@@ -35,13 +43,8 @@ const editorDescriptor = new EditorDescriptor(
3543
Registry.as<IEditorRegistry>(EditorExtensions.Editors)
3644
.registerEditor(editorDescriptor, [new SyncDescriptor(ReleaseNotesInput)]);
3745

38-
if (isMacintosh) {
39-
Registry.as<IGlobalActivityRegistry>(GlobalActivityExtensions)
40-
.registerActivity(UpdateContribution2);
41-
} else {
42-
Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions)
43-
.registerWorkbenchAction(new SyncActionDescriptor(ShowCurrentReleaseNotesAction, ShowCurrentReleaseNotesAction.ID, ShowCurrentReleaseNotesAction.LABEL), 'Open Release Notes');
44-
}
46+
Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions)
47+
.registerWorkbenchAction(new SyncActionDescriptor(ShowCurrentReleaseNotesAction, ShowCurrentReleaseNotesAction.ID, ShowCurrentReleaseNotesAction.LABEL), 'Open Release Notes');
4548

4649
// Configuration: Update
4750
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);

src/vs/workbench/parts/update/electron-browser/update.ts

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import { asText } from 'vs/base/node/request';
2323
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2424
import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO';
2525
import { IOpenerService } from 'vs/platform/opener/common/opener';
26+
import { ICommandService } from 'vs/platform/commands/common/commands';
2627
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
2728
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
28-
import { IUpdateService } from 'vs/platform/update/common/update';
29+
import { IUpdateService, State as UpdateState } from 'vs/platform/update/common/update';
2930
import * as semver from 'semver';
3031
import { OS } from 'vs/base/common/platform';
3132

@@ -191,24 +192,22 @@ const LinkAction = (id: string, message: string, licenseUrl: string) => new Acti
191192
() => { window.open(licenseUrl); return TPromise.as(null); }
192193
);
193194

194-
export class UpdateContribution implements IWorkbenchContribution {
195+
export class ProductContribution implements IWorkbenchContribution {
195196

196197
private static KEY = 'releaseNotes/lastVersion';
197-
getId() { return 'vs.update'; }
198+
getId() { return 'vs.product'; }
198199

199200
constructor(
200201
@IStorageService storageService: IStorageService,
201202
@IInstantiationService instantiationService: IInstantiationService,
202203
@IMessageService messageService: IMessageService,
203-
@IUpdateService updateService: IUpdateService,
204204
@IWorkbenchEditorService editorService: IWorkbenchEditorService
205205
) {
206-
const lastVersion = storageService.get(UpdateContribution.KEY, StorageScope.GLOBAL, '');
206+
const lastVersion = storageService.get(ProductContribution.KEY, StorageScope.GLOBAL, '');
207207

208-
// was there an update?
208+
// was there an update? if so, open release notes
209209
if (product.releaseNotesUrl && lastVersion && pkg.version !== lastVersion) {
210-
instantiationService.invokeFunction(loadReleaseNotes, pkg.version)
211-
.then(
210+
instantiationService.invokeFunction(loadReleaseNotes, pkg.version).then(
212211
text => editorService.openEditor(instantiationService.createInstance(ReleaseNotesInput, pkg.version, text), { pinned: true }),
213212
() => {
214213
messageService.show(Severity.Info, {
@@ -232,8 +231,19 @@ export class UpdateContribution implements IWorkbenchContribution {
232231
});
233232
}
234233

235-
storageService.store(UpdateContribution.KEY, pkg.version, StorageScope.GLOBAL);
234+
storageService.store(ProductContribution.KEY, pkg.version, StorageScope.GLOBAL);
235+
}
236+
}
237+
238+
export class UpdateContribution implements IWorkbenchContribution {
236239

240+
getId() { return 'vs.update'; }
241+
242+
constructor(
243+
@IInstantiationService instantiationService: IInstantiationService,
244+
@IMessageService messageService: IMessageService,
245+
@IUpdateService updateService: IUpdateService
246+
) {
237247
updateService.onUpdateReady(update => {
238248
const applyUpdateAction = instantiationService.createInstance(ApplyUpdateAction);
239249
const releaseNotesAction = instantiationService.createInstance(ShowReleaseNotesAction, false, update.version);
@@ -266,58 +276,49 @@ export class UpdateContribution implements IWorkbenchContribution {
266276
}
267277
}
268278

269-
export class UpdateContribution2 implements IGlobalActivity {
279+
export class LightUpdateContribution implements IGlobalActivity {
270280

271281
get id() { return 'vs.update'; }
272282
get name() { return 'VS Code'; }
273283
get cssClass() { return 'update-activity'; }
274284

275285
constructor(
276286
@IStorageService storageService: IStorageService,
287+
@ICommandService private commandService: ICommandService,
277288
@IInstantiationService instantiationService: IInstantiationService,
278289
@IMessageService messageService: IMessageService,
279-
@IUpdateService updateService: IUpdateService,
290+
@IUpdateService private updateService: IUpdateService,
280291
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
281292
@IActivityBarService activityBarService: IActivityBarService
282293
) {
283-
// updateService.onUpdateReady(update => {
284-
// const applyUpdateAction = instantiationService.createInstance(ApplyUpdateAction);
285-
// const releaseNotesAction = instantiationService.createInstance(ShowReleaseNotesAction, false, update.version);
286-
287-
// messageService.show(severity.Info, {
288-
// message: nls.localize('updateAvailable', "{0} will be updated after it restarts.", product.nameLong),
289-
// actions: [applyUpdateAction, NotNowAction, releaseNotesAction]
290-
// });
291-
// });
292-
293-
// updateService.onUpdateAvailable(update => {
294-
setTimeout(() => {
295-
const badge = new DotBadge(() => 'UPDATE AVAILABLE');
294+
this.updateService.onUpdateReady(() => {
295+
const badge = new DotBadge(() => nls.localize('updateIsReady', "New update available."));
296296
activityBarService.showGlobalActivity(this.id, badge);
297-
}, 0);
298-
// });
299-
300-
// updateService.onUpdateNotAvailable(explicit => {
301-
// if (!explicit) {
302-
// return;
303-
// }
304-
305-
// messageService.show(severity.Info, nls.localize('noUpdatesAvailable', "There are no updates currently available."));
306-
// });
297+
});
307298

308-
updateService.onError(err => messageService.show(severity.Error, err));
299+
this.updateService.onError(err => messageService.show(severity.Error, err));
309300
}
310301

311302
getActions(): IAction[] {
312-
return [
313-
new Action('foo', 'FOO'),
314-
new Action('bar', 'BAR'),
315-
new Action('foo', 'FOO'),
316-
new Action('bar', 'BAR'),
317-
new Action('foo', 'FOO'),
318-
new Action('bar', 'BAR'),
319-
new Action('foo', 'FOO'),
320-
new Action('bar', 'BAR')
321-
];
303+
switch (this.updateService.state) {
304+
case UpdateState.Uninitialized:
305+
return [new Action('update.notavailable', nls.localize('not available', "Updates Not Available"), undefined, false)];
306+
307+
case UpdateState.CheckingForUpdate:
308+
return [new Action('update.checking', nls.localize('checkingForUpdates', "Checking For Updates..."), undefined, false)];
309+
310+
case UpdateState.UpdateAvailable:
311+
return [new Action('update.installing', nls.localize('installingUpdate', "Installing Update..."), undefined, false)];
312+
313+
case UpdateState.UpdateDownloaded:
314+
return [new Action('update.restart', nls.localize('restartToUpdate', "Restart To Update..."), undefined, true, () =>
315+
this.updateService.quitAndInstall()
316+
)];
317+
318+
default:
319+
return [new Action('update.check', nls.localize('checkForUpdates', "Check For Updates..."), undefined, this.updateService.state === UpdateState.Idle, () =>
320+
this.updateService.checkForUpdates(true)
321+
)];
322+
}
322323
}
323324
}

0 commit comments

Comments
 (0)