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
|
/*******************************************************************************
* Copyright (c) 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
* License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html).
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*eslint-env node */
var express = require('express'),
electron = require('electron'),
autoUpdater = require('./autoUpdater.js'),
bodyParser = require('body-parser'),
prefs = require('./controllers/prefs'),
os = require('os'),
platform = os.platform(),
arch = os.arch(),
version = electron.app.getVersion(),
allPrefs = prefs.readPrefs();
module.exports = {};
module.exports.router = function(options) {
var configParams = options.configParams;
if (!configParams) { throw new Error('options.configParams is required'); }
var feedURL = configParams["orion.autoUpdater.url"];
return express.Router()
.use(bodyParser.json())
.post('/downloadUpdates', function (req, res) {
if (platform === "linux") {
electron.shell.openExternal(feedURL + '/download/channel/' + allPrefs.user.updateChannel + '/linux');
res.status(200).end();
} else {
autoUpdater.setFeedURL(feedURL + '/update/channel/' + allPrefs.user.updateChannel + '/' + platform + '_' + arch + '/' + version);
autoUpdater.checkForUpdates();
res.status(200).end();
}
})
.get("/resolveNewVersion", function (req, res) {
if (!feedURL) {
return res.status(400).end();
}
allPrefs.user.updateChannel = req.query.updateChannel;
prefs.writePrefs(allPrefs);
var resolveURL = feedURL + '/api/resolve?platform=' + platform + '&channel=' + allPrefs.user.updateChannel;
autoUpdater.setResolveURL(resolveURL);
autoUpdater.resolveNewVersion(true);
autoUpdater.on("update-available-manual", function(newVersion) {
res.status(200).end(newVersion); // OK
});
autoUpdater.on("update-not-available", function() {
res.status(204).end(); // no content
});
autoUpdater.on("update-error", function(error) {
console.log(error);
res.status(400).end(); // client error
})
});
};
|