@@ -12,6 +12,7 @@ export default class PushPullViewModel {
12
12
token : ?string ;
13
13
inFlightRequests : number ;
14
14
emitter : Emitter ;
15
+ progress : number ;
15
16
16
17
constructor ( gitStore : GitStore ) {
17
18
this . inFlightRequests = 0
@@ -36,7 +37,8 @@ export default class PushPullViewModel {
36
37
let index = 0
37
38
for ( const remote of remotes ) {
38
39
await this . gitService . fetch ( remote , creds , localProgress => { // eslint-disable-line babel/no-await-in-loop
39
- console . log ( 'fetch progress' , ( localProgress + index ) / remotes . length )
40
+ this . progress = ( localProgress + index ) / remotes . length
41
+ this . emitter . emit ( 'did-update' )
40
42
} )
41
43
index ++
42
44
}
@@ -46,27 +48,35 @@ export default class PushPullViewModel {
46
48
pull ( ) : Promise < void > {
47
49
return this . performNetworkAction ( ( ) => {
48
50
return this . gitService . pull ( this . gitStore . branchName , this . getCreds ( ) , progress => {
49
- console . log ( 'pull progress' , progress )
51
+ this . progress = progress
52
+ this . emitter . emit ( 'did-update' )
50
53
} )
51
54
} )
52
55
}
53
56
54
57
push ( ) : Promise < void > {
55
58
return this . performNetworkAction ( ( ) => {
56
59
return this . gitService . push ( this . gitStore . branchName , this . getCreds ( ) , progress => {
57
- console . log ( 'push progress' , progress )
60
+ this . progress = progress
61
+ this . emitter . emit ( 'did-update' )
58
62
} )
59
63
} )
60
64
}
61
65
66
+ getProgressPercentage ( ) : number {
67
+ return this . progress * 100
68
+ }
69
+
62
70
async performNetworkAction ( fn : ( ) = > Promise < void > ) : Promise < void > {
71
+ this. progress = 0
63
72
this . inFlightRequests ++
64
73
this . emitter . emit ( 'did-update' )
65
74
66
75
try {
67
76
await fn ( )
68
77
} finally {
69
78
this . inFlightRequests --
79
+ this . progress = 0
70
80
this . emitter . emit ( 'did-update' )
71
81
}
72
82
}
0 commit comments