git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 01d1fe807ecac5563dd29fe54cc93a07904823e2

Files: 01d1fe807ecac5563dd29fe54cc93a07904823e2 / modules / app / sync / external-handler / git.js

986 bytesRaw
1const nest = require('depnest')
2const {shell} = require('electron')
3const net = require('net')
4
5exports.gives = nest('app.sync.externalHandler')
6
7var externalViewer = 'http://git.scuttlebot.io'
8var localViewer = 'http://localhost:7718'
9
10var gitMessageTypes = [
11 'git-repo',
12 'git-update',
13 'issue',
14 'issue-edit',
15 'pull-request'
16]
17
18exports.create = (api) => {
19 return nest('app.sync.externalHandler', function (msg) {
20 if (!gitMessageTypes.includes(msg.value.content.type)) return
21 return function gitHandler (id) {
22 portInUse(7718, (useLocal) => {
23 shell.openExternal(`${useLocal ? localViewer : externalViewer}/${encodeURIComponent(id)}`)
24 })
25 }
26 })
27}
28
29function portInUse (port, callback) {
30 // super hacky check!
31 var server = net.createServer(function (socket) {})
32 server.listen(port, '127.0.0.1')
33 server.on('error', function (e) {
34 callback(true)
35 })
36 server.on('listening', function (e) {
37 server.close()
38 callback(false)
39 })
40}
41

Built with git-ssb-web