77
88import { TPromise } from 'vs/base/common/winjs.base' ;
99import { IChannel , eventToCall , eventFromCall } from 'vs/base/parts/ipc/common/ipc' ;
10- import Event from 'vs/base/common/event' ;
10+ import Event , { Emitter , any , mapEvent } from 'vs/base/common/event' ;
11+ import { onUnexpectedError } from 'vs/base/common/errors' ;
12+ import { memoize } from 'vs/base/common/decorators' ;
1113import { IUpdateService , IRawUpdate , State , IUpdate } from './update' ;
1214
1315export interface IUpdateChannel extends IChannel {
@@ -18,6 +20,7 @@ export interface IUpdateChannel extends IChannel {
1820 call ( command : 'event:onStateChange' ) : TPromise < void > ;
1921 call ( command : 'checkForUpdates' , arg : boolean ) : TPromise < IUpdate > ;
2022 call ( command : 'quitAndInstall' ) : TPromise < void > ;
23+ call ( command : '_getInitialState' ) : TPromise < State > ;
2124 call ( command : string , arg ?: any ) : TPromise < any > ;
2225}
2326
@@ -34,6 +37,7 @@ export class UpdateChannel implements IUpdateChannel {
3437 case 'event:onStateChange' : return eventToCall ( this . service . onStateChange ) ;
3538 case 'checkForUpdates' : return this . service . checkForUpdates ( arg ) ;
3639 case 'quitAndInstall' : return this . service . quitAndInstall ( ) ;
40+ case '_getInitialState' : return TPromise . as ( this . service . state ) ;
3741 }
3842 return undefined ;
3943 }
@@ -55,14 +59,25 @@ export class UpdateChannelClient implements IUpdateService {
5559 private _onUpdateReady = eventFromCall < IRawUpdate > ( this . channel , 'event:onUpdateReady' ) ;
5660 get onUpdateReady ( ) : Event < IRawUpdate > { return this . _onUpdateReady ; }
5761
58- private _onStateChange = eventFromCall < State > ( this . channel , 'event:onStateChange' ) ;
59- get onStateChange ( ) : Event < State > { return this . _onStateChange ; }
62+ private _onInitialStateChange = new Emitter < State > ( ) ;
63+ private _onRemoteStateChange = eventFromCall < State > ( this . channel , 'event:onStateChange' ) ;
64+
65+ @memoize
66+ get onStateChange ( ) : Event < State > {
67+ const result = any ( this . _onInitialStateChange . event , this . _onRemoteStateChange ) ;
68+
69+ return mapEvent ( result , state => {
70+ this . _state = state ;
71+ return state ;
72+ } ) ;
73+ }
6074
6175 private _state : State = State . Uninitialized ;
6276 get state ( ) : State { return this . _state ; } ;
6377
64- constructor ( private channel : IChannel ) {
65- this . onStateChange ( state => this . _state = state ) ;
78+ constructor ( private channel : IUpdateChannel ) {
79+ channel . call ( '_getInitialState' )
80+ . done ( state => this . _onInitialStateChange . fire ( state ) , onUnexpectedError ) ;
6681 }
6782
6883 checkForUpdates ( explicit : boolean ) : TPromise < IUpdate > {
0 commit comments