git ssb

10+

Matt McKegg / patchwork



Tree: cfcee0de2ad3f7e772827e71b22f53dcb961e5f4

Files: cfcee0de2ad3f7e772827e71b22f53dcb961e5f4 / lib / latest-update.js

1020 bytesRaw
1var https = require('https')
2var packageInfo = require('../package.json')
3var compareVersion = require('compare-version')
4var Value = require('mutant/value')
5var computed = require('mutant/computed')
6
7module.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