@@ -17,16 +17,19 @@ function isRemoteOperation(operation: Operation): boolean {
1717
1818export class AutoFetcher {
1919
20- private static readonly Period = 3 * 60 * 1000 /* three minutes */ ;
2120 private static DidInformUser = 'autofetch.didInformUser' ;
2221
23- private _onDidChange = new EventEmitter < boolean > ( ) ;
22+ private _onDidChange = new EventEmitter < boolean | number > ( ) ;
2423 private onDidChange = this . _onDidChange . event ;
2524
2625 private _enabled : boolean = false ;
2726 get enabled ( ) : boolean { return this . _enabled ; }
2827 set enabled ( enabled : boolean ) { this . _enabled = enabled ; this . _onDidChange . fire ( enabled ) ; }
2928
29+ private _timeout : number = workspace . getConfiguration ( 'git' ) . get < number > ( 'autofetchPeriod' , 3 ) * 60 * 1000 ;
30+ private get timeout ( ) : number { return this . _timeout ; }
31+ private set timeout ( minutes : number ) { this . _timeout = minutes * 60 * 1000 ; this . _onDidChange . fire ( minutes ) ; }
32+
3033 private disposables : Disposable [ ] = [ ] ;
3134
3235 constructor ( private repository : Repository , private globalState : Memento ) {
@@ -70,19 +73,19 @@ export class AutoFetcher {
7073
7174 private onConfiguration ( ) : void {
7275 const gitConfig = workspace . getConfiguration ( 'git' ) ;
76+ const minutes = gitConfig . get < number > ( 'autofetchPeriod' , 3 ) ;
77+ const autofetch = gitConfig . get < boolean > ( 'autofetch' ) ;
7378
74- if ( gitConfig . get < boolean > ( 'autofetch' ) === false ) {
75- this . disable ( ) ;
76- } else {
77- this . enable ( ) ;
79+ if ( this . timeout !== minutes ) {
80+ this . timeout = minutes ;
7881 }
79- }
8082
81- enable ( ) : void {
82- if ( this . enabled ) {
83- return ;
83+ if ( this . enabled !== autofetch ) {
84+ autofetch ? this . enable ( ) : this . disable ( ) ;
8485 }
86+ }
8587
88+ enable ( ) : void {
8689 this . enabled = true ;
8790 this . run ( ) ;
8891 }
@@ -111,9 +114,9 @@ export class AutoFetcher {
111114 return ;
112115 }
113116
114- const timeout = new Promise ( c => setTimeout ( c , AutoFetcher . Period ) ) ;
115- const whenDisabled = eventToPromise ( filterEvent ( this . onDidChange , enabled => ! enabled ) ) ;
116- await Promise . race ( [ timeout , whenDisabled ] ) ;
117+ const timeout = new Promise ( c => setTimeout ( c , this . timeout ) ) ;
118+ const onChanged = eventToPromise ( filterEvent ( this . onDidChange , ( ) => true ) ) ;
119+ await Promise . race ( [ timeout , onChanged ] ) ;
117120 }
118121 }
119122
0 commit comments