forked from shadowsocks/shadowsocks-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
73 lines (67 loc) · 1.95 KB
/
update.js
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
// Generated by CoffeeScript 1.8.0
(function() {
var checkUpdate, compareVersion, platformMap, util;
util = require('util');
platformMap = {
'win32': 'win',
'darwin': 'osx',
'linux': 'linux'
};
compareVersion = function(l, r) {
var i, lp, ls, rp, rs, _i, _ref;
ls = l.split('.');
rs = r.split('.');
for (i = _i = 0, _ref = Math.min(ls.length, rs.length); 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
lp = ls[i];
rp = rs[i];
if (lp !== rp) {
return lp - rp;
}
}
return ls.length - rs.length;
};
checkUpdate = function(callback) {
var $, arch, e, packageInfo, platform, re, version;
if (callback != null) {
try {
packageInfo = require('./package.json');
} catch (_error) {
e = _error;
util.log(e);
return;
}
version = packageInfo.version;
arch = process.arch;
platform = platformMap[process.platform];
$ = window.$;
re = /^.*shadowsocks-gui-([\d\.]+)-(\w+)-(\w+)\..*$/;
return $.get('https://sourceforge.net/api/file/index/project-id/1817190/path/dist/mtime/desc/limit/4/rss', function(data) {
var r, results, _i, _len;
results = [];
$(data).find('content').each(function() {
var g, url;
url = $(this).attr('url');
g = re.exec(url);
if (g != null) {
return results.push(g);
}
});
results.sort(function(l, r) {
return -compareVersion(l[1], r[1]);
});
for (_i = 0, _len = results.length; _i < _len; _i++) {
r = results[_i];
if ((r[2] === platform) && (r[3] === arch)) {
if (compareVersion(r[1], version) > 0) {
callback(r[0], r[1]);
return;
}
}
}
}).fail(function() {
return alert("error");
});
}
};
exports.checkUpdate = checkUpdate;
}).call(this);