Skip to content

Commit 66113ef

Browse files
committed
Fix #916 Show installation progress based on number of selected components
1 parent 3e993ca commit 66113ef

8 files changed

Lines changed: 48 additions & 58 deletions

File tree

browser/directives/progressBar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88
<div class="progress progress-label-top-right">
99
<div class="progress-bar"
10-
ng-class="{'progress-determinate active': progress.status == 'Installing' || progress.status == 'Setting up' || progress.status.indexOf('Waiting') > -1 || progress.status.indexOf('Verifying') > -1, 'progress-bar-danger': progress.status.indexOf('Failed') > -1}"
10+
ng-class="{'progress-bar-danger': progress.status.indexOf('Failed') > -1}"
1111
role="progressbar" aria-valuenow="{{progress.current}}" aria-valuemin="{{progress.min}}" aria-valuemax="{{progress.max}}"
1212
style="width: {{progress.current}}%; animation: progress-bar-stripes 2s infinite steps(15);">
1313
<span>{{progress.label}}</span>

browser/model/helpers/installer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class Installer {
143143

144144
succeed(done) {
145145
if (done) {
146-
this.progress.setComplete();
147146
this.success();
148147
}
149148
}

browser/pages/install/controller.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class InstallController {
1212
this.$timeout = $timeout;
1313
this.installerDataSvc = installerDataSvc;
1414
this.electron = electron;
15+
this.electron.ipcRenderer.setMaxListeners(0);
1516
this.failedDownloads = new Set();
1617
this.totalAmount = 0;
1718
this.installerDataSvc.setupTargetFolder();
@@ -49,6 +50,16 @@ class InstallController {
4950
}
5051
}
5152
this.$scope.data = this.data;
53+
54+
this.electron.ipcRenderer.on('installComplete', (event, key)=>{
55+
if(key == 'all') {
56+
this.itemProgress.current = 100;
57+
this.$timeout();
58+
this.$timeout(()=>{
59+
this.installerDataSvc.router.go('start');
60+
},700);
61+
}
62+
});
5263
}
5364

5465
processInstallable(key, value) {
@@ -84,6 +95,17 @@ class InstallController {
8495
}
8596

8697
processInstall() {
98+
99+
let totalItems = 0;
100+
for (let [key, value] of this.installerDataSvc.allInstallables().entries()) {
101+
if(!value.isSkipped()) {
102+
totalItems++;
103+
}
104+
}
105+
this.itemProgress.setStatus('Installing');
106+
this.itemProgress.setTotalAmount(totalItems);
107+
this.itemProgress.setCurrent(1);
108+
87109
for (let [key, value] of this.installerDataSvc.allInstallables().entries()) {
88110
if(!value.isSkipped()) {
89111
this.triggerInstall(key, value, this.itemProgress);
@@ -95,6 +117,7 @@ class InstallController {
95117
this.installerDataSvc.startInstall(installableKey);
96118
installableValue.install(progress,
97119
() => {
120+
this.itemProgress.setCurrent(this.itemProgress.currentAmount+1);
98121
this.installerDataSvc.installDone(progress, installableKey);
99122
},
100123
(error) => {
@@ -158,7 +181,7 @@ class ProgressState {
158181
}
159182

160183
setCurrent(newVal) {
161-
if (newVal > this.currentAmount && newVal <= this.totalAmount) {
184+
if (newVal <= this.totalAmount) {
162185
this.lastAmount = this.currentAmount;
163186
this.currentAmount = newVal;
164187

@@ -167,8 +190,13 @@ class ProgressState {
167190
this.durationFormat.units.push('s');
168191
}
169192

170-
this.current = Math.round(this.currentAmount / this.totalAmount * 100);
171-
this.label = this.sizeInKB(this.currentAmount) + ' / ' + this.sizeInKB(this.totalAmount) + ' (' + this.current + '%), ' + this.durationFormat(remaining) + ' left';
193+
if (this.status === 'Downloading') {
194+
this.current = Math.round(this.currentAmount / this.totalAmount * 100);
195+
this.label = this.sizeInKB(this.currentAmount) + ' / ' + this.sizeInKB(this.totalAmount) + ' (' + this.current + '%), ' + this.durationFormat(remaining) + ' left';
196+
} else if(this.status === 'Installing'){
197+
this.current = Math.round((this.currentAmount-1) / this.totalAmount * 100);
198+
this.label = this.currentAmount + ' out of ' + this.totalAmount ;
199+
}
172200
this.$timeout();
173201
}
174202
}
@@ -183,18 +211,6 @@ class ProgressState {
183211
}
184212

185213
setStatus(newStatus) {
186-
if (newStatus === this.status) {
187-
return;
188-
}
189-
if (newStatus !== 'Downloading') {
190-
this.current = 100;
191-
this.label = '';
192-
} else {
193-
this.current = 0;
194-
this.label = 0 + '%';
195-
this.currentAmount = 0;
196-
// this.totalAmount = 0;
197-
}
198214
this.status = newStatus;
199215
this.$timeout();
200216
}

browser/services/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class InstallerDataService {
285285
Logger.info('All installs complete');
286286
this.installing = false;
287287
this.ipcRenderer.send('installComplete', 'all');
288-
this.router.go('start');
288+
// this.router.go('start');
289289
}
290290
}
291291

test/mock/electron.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
import EventEmitter from 'events';
4+
35
function electron() {
46
let electronWindow = {
57
close() {},
@@ -30,9 +32,11 @@ function electron() {
3032
let shell = {
3133
openExternal() {}
3234
};
35+
let ipcRenderer = new EventEmitter();
3336
return {
3437
remote,
35-
shell
38+
shell,
39+
ipcRenderer
3640
};
3741
}
3842

test/unit/model/helpers/installer-test.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,6 @@ describe('Installer', function() {
343343
});
344344

345345
describe('succeed', function() {
346-
it('should set progress to complete when the input is truthy', function() {
347-
let spy = sandbox.spy(fakeProgress, 'setComplete');
348-
installer.succeed(true);
349-
350-
expect(spy).to.have.been.calledOnce;
351-
});
352-
353346
it('should not succeed with a falsey input', function() {
354347
let spy = sandbox.spy(fakeProgress, 'setComplete');
355348
installer.succeed(false);

test/unit/pages/install/controller-test.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Install controller', function() {
5353
describe('constrution', function() {
5454
it('should process all installables', function() {
5555
let stub = sandbox.stub(InstallController.prototype, 'processInstallable').returns();
56-
new InstallController({}, {}, installerDataSvc);
56+
new InstallController({}, {}, installerDataSvc, new ElectronMock());
5757

5858
expect(stub).calledOnce;
5959
expect(stub).calledWith(VirtualBoxInstall.KEY, vbox);
@@ -63,7 +63,7 @@ describe('Install controller', function() {
6363
let stub = sandbox.stub(installerDataSvc, 'setupDone').returns();
6464
sandbox.stub(InstallController.prototype, 'processInstallable').returns();
6565
sandbox.stub(vbox, 'isSkipped').returns(true);
66-
new InstallController({}, {}, installerDataSvc);
66+
new InstallController({}, {}, installerDataSvc, new ElectronMock());
6767
expect(stub).calledOnce;
6868
});
6969
});
@@ -87,14 +87,14 @@ describe('Install controller', function() {
8787
});
8888

8989
it('should trigger download on not downloaded installables', function() {
90-
new InstallController({}, timeoutStub, installerDataSvc);
90+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
9191

9292
expect(dlStub).calledOnce;
9393
expect(dlStub).calledWith('virtualbox', vbox);
9494
});
9595

9696
it('should not trigger download on already downloaded items', function() {
97-
new InstallController({}, timeoutStub, installerDataSvc);
97+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
9898

9999
});
100100
});
@@ -109,7 +109,7 @@ describe('Install controller', function() {
109109

110110
it('data service should register the new downloads', function() {
111111
let spy = sandbox.spy(installerDataSvc, 'startDownload');
112-
new InstallController({}, timeoutStub, installerDataSvc);
112+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
113113

114114
expect(spy).calledOnce;
115115
expect(spy).calledWith('virtualbox');
@@ -121,7 +121,7 @@ describe('Install controller', function() {
121121
it('should call the installables downloadInstaller method', function() {
122122
sandbox.stub(installerDataSvc, 'startDownload').returns();
123123

124-
new InstallController({}, timeoutStub, installerDataSvc);
124+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
125125
expect(vboxStub).calledOnce;
126126
});
127127
});
@@ -138,21 +138,21 @@ describe('Install controller', function() {
138138
it.skip('logs error in case of install failed', function() {
139139
vbox.install.restore();
140140
sandbox.stub(vbox, 'install').callsArgWith(2, 'Error');
141-
new InstallController({}, timeoutStub, installerDataSvc);
141+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
142142
expect(errorStub).calledTwice;
143143
});
144144

145145
it.skip('should call the installables install method', function() {
146146
sandbox.stub(installerDataSvc, 'startInstall').returns();
147147

148-
new InstallController({}, timeoutStub, installerDataSvc);
148+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
149149
expect(vboxStub).calledOnce;
150150
});
151151

152152
it.skip('should call data services installDone when install finishes', function() {
153153
sandbox.stub(installerDataSvc, 'startInstall').returns();
154154

155-
new InstallController({}, timeoutStub, installerDataSvc);
155+
new InstallController({}, timeoutStub, installerDataSvc, new ElectronMock());
156156

157157
expect(doneStub).calledOnce;
158158
expect(doneStub).calledWith(sinon.match.any, 'virtualbox');
@@ -173,18 +173,13 @@ describe('Install controller', function() {
173173
});
174174
});
175175
describe('setCurrent', function() {
176-
it('should do nothing if new current progress value is the same', function() {
177-
let progress = new ProgressState();
178-
progress.$timeout = sandbox.stub().yields();
179-
progress.setCurrent(0);
180-
expect(progress.$timeout).to.be.not.called;
181-
});
182176
describe('should update', function() {
183177
let progress;
184178
beforeEach(function() {
185179
progress = new ProgressState();
186180
progress.$timeout = sinon.stub();
187181
progress.$scope = {$apply:sinon.stub()};
182+
progress.setStatus('Downloading');
188183
progress.setTotalAmount(1000);
189184
progress.setCurrent(100);
190185
});
@@ -292,12 +287,6 @@ describe('Install controller', function() {
292287
it('sets status to "Complete"', function() {
293288
expect(progress.status).equals('Complete');
294289
});
295-
it('sets label to 100%', function() {
296-
expect(progress.label).equals('');
297-
});
298-
it('sets current prcentage to 100', function() {
299-
expect(progress.current).equals(100);
300-
});
301290
});
302291
describe('calculateTime', function() {
303292
let progress;

test/unit/services/data-test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,6 @@ describe('InstallerDataService', function() {
353353
expect(spy).calledWith('installComplete', 'all');
354354
});
355355

356-
it('setupDone should switch to final page when all installs have finished', function() {
357-
let spy = sandbox.spy(svc.router, 'go');
358-
359-
svc.setupDone(fakeProgress, 'jdk');
360-
svc.setupDone(fakeProgress, 'vbox');
361-
362-
expect(svc.installing).to.be.false;
363-
expect(spy).calledOnce;
364-
expect(spy).calledWith('start');
365-
});
366-
367356
it('setupDone should not log info message for skipped installer', function() {
368357
sandbox.stub(jdk, 'isSkipped').returns(true);
369358
Logger.info.reset();

0 commit comments

Comments
 (0)