@@ -23,9 +23,10 @@ import { asText } from 'vs/base/node/request';
2323import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
2424import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO' ;
2525import { IOpenerService } from 'vs/platform/opener/common/opener' ;
26+ import { ICommandService } from 'vs/platform/commands/common/commands' ;
2627import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
2728import { 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' ;
2930import * as semver from 'semver' ;
3031import { 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