forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-updater.js
55 lines (45 loc) · 1.27 KB
/
run-updater.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
var _ = require('underscore');
var Fiber = require('fibers');
var inFiber = require('./fiber-helpers.js').inFiber;
var Updater = function () {
var self = this;
self.timer = null;
};
// XXX make it take a runLog?
// XXX need to deal with updater writing messages (bypassing old
// stdout interception.. maybe it should be global after all..)
_.extend(Updater.prototype, {
start: function () {
var self = this;
if (self.timer)
throw new Error("already running?");
// Check twice a day.
self.timer = setInterval(inFiber(function () {
self._check();
}), 12*60*60*1000);
// Also start a check now, but don't block on it.
new Fiber(function () {
self._check();
}).run();
},
_check: function () {
var self = this;
var updater = require('./updater.js');
try {
updater.tryToDownloadUpdate({showBanner: true});
} catch (e) {
// oh well, this was the background. no need to show any errors.
return;
}
},
// Returns immediately. However if an update check is currently
// running it will complete in the background. Idempotent.
stop: function () {
var self = this;
if (self.timer)
return;
clearInterval(self.timer);
self.timer = null;
}
});
exports.Updater = Updater;