-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcontroller.js
More file actions
293 lines (262 loc) · 9.88 KB
/
controller.js
File metadata and controls
293 lines (262 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
'use strict';
import Logger from '../../services/logger';
import pgp from '../../services/openpgp';
import Platform from '../../services/platform';
import ComponentLoader from '../../services/componentLoader';
import meta from '../../services/metadata';
import request from 'request';
import pify from 'pify';
import electron from 'electron';
class ConfirmController {
constructor($scope, $state, $timeout, installerDataSvc, electron) {
this.router = $state;
this.sc = $scope;
this.timeout = $timeout;
this.installerDataSvc = installerDataSvc;
this.electron = electron;
this.installedSearchNote = '';
this.isDisabled = false;
this.numberOfExistingInstallations = 0;
this.installables = {};
$scope.checkboxModel = {};
$scope.platform = Platform.OS;
$scope.detectionStyle = false;
$scope.virtualization = true;
this.sc.$watch('$viewContentLoaded', ()=>{
this.initPage();
});
this.loader = new ComponentLoader(installerDataSvc);
}
loadModel() {
this.loader.loadComponents();
for (let [key, value] of this.installerDataSvc.allInstallables().entries()) {
this.sc.checkboxModel[key] = value;
let that = this;
this.sc.$watch(`checkboxModel.${key}.selectedOption`, function watchInstallSelectionChange() {
that.sc.checkboxModel[key].validateVersion();
});
}
this.sc.isConfigurationValid = this.isConfigurationValid;
this.electron.remote.getCurrentWindow().addListener('focus', ()=> {
this.timeout(() => {
this.activatePage();
this.sc.$apply();
});
});
}
checkForUpdates() {
this.isDisabled = true;
this.installedSearchNote = 'The system is checking for updates';
return this.timeout(true).then(()=> {
return pify(request)('https://raw.githubusercontent.com/dgolovin/developer-platform-install-repo/master/requirements.json').then((value)=>{
pgp(this.pgpPublicKey, value.body).then(({text, valid, error})=>{
if(!error && valid) {
let remoteReqs = meta(JSON.parse(text), Platform.OS);
let opt = {
type: 'none',
buttons: ['Yes', 'No'],
defaultId: 0,
cancelId: 1,
message: 'There is new set of components available for installation.\nWould you like to use it?'
};
if(this.isUpdateRequired(this.installerDataSvc.requirements, remoteReqs) && 0 === electron.remote.dialog.showMessageBox(electron.remote.getCurrentWindow(), opt)) {
this.installerDataSvc.clearItemsToInstall();
this.installerDataSvc.loadRequirements(remoteReqs);
}
}
this.loadModel();
});
});
});
}
isUpdateRequired(oldr, newr) {
let res = false;
for(let object in newr) {
if(oldr[object] === undefined || (oldr[object] && oldr[object].version !== newr[object].version)) {
res = true;
break;
}
}
return res;
}
initPage() {
return Promise.resolve().then(()=> {
return this.checkForUpdates();
}).then(()=> {
this.isDisabled = false;
return this.detectInstalledComponents();
}).then(()=> {
this.graph = ComponentLoader.loadGraph(this.installerDataSvc);
this.installWatchers();
return Promise.resolve();
}).then(
()=> this.setIsDisabled()
).catch((error)=> {
console.error(error);
this.setIsDisabled();
});
}
activatePage() {
return this.detectInstalledComponents().then(
()=> this.setIsDisabled()
).catch((error)=> {
Logger.error(error);
this.setIsDisabled();
});
}
installWatchers() {
let graph = this.graph;
let nodes = graph.overallOrder() ;
let checkboxModel = this.sc.checkboxModel;
for (let node of nodes) {
checkboxModel[node].dependenciesOf = [];
for(let dependant of this.graph.dependantsOf(node)) {
checkboxModel[node].dependenciesOf.push(checkboxModel[dependant]);
}
checkboxModel[node].references=0;
}
for (let node of nodes) {
function watchComponent(newv, oldv) {
let installer = checkboxModel[node];
if(installer.isSelected()) {
for(let dep of graph.dependenciesOf(node)) {
let depInstaller = checkboxModel[dep];
if(depInstaller.references === 0 && depInstaller.isNotDetected()) {
depInstaller.selectedOption = 'install';
}
depInstaller.references++;
}
} else if(!installer.isSelected() && oldv === 'install') {
for(let dep of graph.dependenciesOf(node)) {
let depInstaller = checkboxModel[dep];
depInstaller.references--;
if(depInstaller.references === 0) {
depInstaller.selectedOption = 'detected';
}
}
}
}
this.sc.$watch(`checkboxModel.${node}.selectedOption`, watchComponent);
}
}
detectInstalledComponents() {
if(!this.isDisabled) {
this.isDisabled = true;
this.installedSearchNote = 'The system is checking if you have any installed components.';
let detectors = [];
for (var installer of this.installerDataSvc.allInstallables().values()) {
detectors.push(installer.detectExistingInstall());
}
this.detection = this.timeout(true).then(()=>{
return Promise.all(detectors);
});
}
return this.detection;
}
download(url) {
this.electron.shell.openExternal(url);
}
// Prep the install location path for each product, then go to the next page.
install() {
if (this.sc.checkboxModel.hyperv && this.sc.checkboxModel.hyperv.isConfigured()) {
this.loader.removeComponent('virtualbox');
} else {
this.loader.removeComponent('hyperv');
}
let possibleComponents = ['virtualbox', 'jdk', 'devstudio', 'jbosseap', 'cygwin', 'cdk', 'kompose', 'fuseplatform', 'fuseplatformkaraf'];
for (let i = 0; i < possibleComponents.length; i++) {
let component = this.installerDataSvc.getInstallable(possibleComponents[i]);
if (component) {
possibleComponents[i] = component.getLocation();
} else {
possibleComponents[i] = undefined;
}
}
this.electron.remote.getCurrentWindow().removeAllListeners('focus');
this.installerDataSvc.setup(...possibleComponents);
this.router.go('install');
}
setIsDisabled() {
// Uncomment the timeout to see the initial disabled view.
this.timeout( () => {
// Switch this boolean flag when the app is done looking for existing installations.
this.isDisabled = !this.isDisabled;
this.numberOfExistingInstallations = 0;
// Count the number of existing installations.
for (var [, value] of this.installerDataSvc.allInstallables()) {
if (value.hasOption('detected')) {
++this.numberOfExistingInstallations;
}
}
if (this.numberOfExistingInstallations == 1) {
this.installedSearchNote = ` We found ${this.numberOfExistingInstallations} installed component`;
} else if (this.numberOfExistingInstallations > 1) {
this.installedSearchNote = ` We found ${this.numberOfExistingInstallations} installed components`;
} else {
this.installedSearchNote = '';
}
// Call the digest cycle so that the view gets updated.
this.sc.$apply();
});
}
isConfigurationValid() {
let result = true;
for (let [, value] of this.installerDataSvc.allInstallables().entries()) {
if(! (result = value.isConfigurationValid())) {
break;
}
}
return result && this.isAtLeastOneSelected();
}
isAtLeastOneSelected() {
for (var [, value] of this.installerDataSvc.allInstallables()) {
if(!value.isSkipped()) {
return true;
}
}
return false;
}
exit() {
Logger.info('Closing the installer window');
this.electron.remote.getCurrentWindow().close();
}
back() {
Logger.info('Going back a page');
this.electron.remote.getCurrentWindow().removeAllListeners('focus');
this.router.go('location');
}
get pgpPublicKey() {
return `-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFl45PABCADa3JMtyxLpEvxiqFsqM0D7p+R5bG4WDUW2Gf3A4olL3Ba1dMbY
XuVKN2VVWF0eaX/kkPFWFQQ/zUbBR5A8BcCzWrVNm7NvbSxkwqS8U8imc+0QYz6f
RQfYvzGaN3rg2EJ4XiGy5M7nVoPmwk9xqbhJxxv3d507oPDN1FOnoTY68Y+GbiUM
HF3mFlBtQwxhGxlFhwPABmHypfeBCk36s0TzzvAekNcT8ROuWM+68KjtZEbizQ4J
0ZYeLixdTyN3em4ve+hFFjiQOZbh5PKzrSP8nw1EFoAdHnefO/2vUe6pp3G8y8CB
zlT2ZU2kuFsP7I5HeZoGi4DbbXgJyqhp4jGrABEBAAG0S0RlbmlzIEdvbG92aW4g
KFRlc3Qgc2lnbmluZyBhbm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
zMlxS8jFPEeBPA7EI4bDQCdg/kBK9C89s2xmZOxz3PtCzoMtj9KICvLzCf0OX1hR
Y8WRZUzrkAkouuli0sfWGIsHSEPFCrNdKdoIud0Klrc/ATMD0tDjz7MEl7brEC08
vRYoPDOBq3YXZ0LdaZwVObM7KV0Ncw2YWg4=
=uZLc
-----END PGP PUBLIC KEY BLOCK-----
`;
}
}
ConfirmController.$inject = ['$scope', '$state', '$timeout', 'installerDataSvc', 'electron'];
export default ConfirmController;