Files: f35f3abb7b44bd982ed14b0000ec35da8641afe3 / lib / latest-update.js
1020 bytesRaw
1 | var https = require('https') |
2 | var packageInfo = require('../package.json') |
3 | var compareVersion = require('compare-version') |
4 | var Value = require('mutant/value') |
5 | var computed = require('mutant/computed') |
6 | |
7 | module.exports = function () { |
8 | var update = Value() |
9 | var hidden = Value(false) |
10 | update.sync = Value(false) |
11 | var version = packageInfo.version |
12 | https.get({ |
13 | host: 'api.github.com', |
14 | path: '/repos/ssbc/patchwork/releases/latest', |
15 | headers: { |
16 | 'user-agent': `Patchwork v${version}` |
17 | } |
18 | }, function (res) { |
19 | if (res.statusCode === 200) { |
20 | var result = '' |
21 | res.on('data', (x) => { |
22 | result += x |
23 | }).on('end', () => { |
24 | var info = JSON.parse(result) |
25 | if (compareVersion(info.tag_name.slice(1), version) > 0) { |
26 | update.set(info.tag_name.slice(1)) |
27 | } |
28 | update.sync.set(true) |
29 | }) |
30 | } |
31 | }) |
32 | |
33 | var obs = computed([update, hidden], (update, hidden) => update && !hidden ? update : false) |
34 | obs.ignore = () => hidden.set(true) |
35 | return obs |
36 | } |
37 |
Built with git-ssb-web