Files: c173c2b41b860fbb9c38b6c51a466f9652d0461f / modules / app / sync / external-handler / git.js
1020 bytesRaw
1 | const nest = require('depnest') |
2 | const {shell} = require('electron') |
3 | const net = require('net') |
4 | |
5 | exports.gives = nest('app.sync.externalHandler') |
6 | |
7 | var externalViewer = 'http://git.scuttlebot.io' |
8 | var localViewer = 'http://localhost:7718' |
9 | |
10 | var gitMessageTypes = [ |
11 | 'git-repo', |
12 | 'git-update', |
13 | 'issue', |
14 | 'issue-edit', |
15 | 'pull-request' |
16 | ] |
17 | |
18 | exports.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 | |
29 | function portInUse (port, cb) { |
30 | /* eslint-disable standard/no-callback-literal */ |
31 | // super hacky check! |
32 | var server = net.createServer(function (socket) {}) |
33 | server.listen(port, '127.0.0.1') |
34 | server.on('error', function (e) { |
35 | cb(true) |
36 | }) |
37 | server.on('listening', function (e) { |
38 | server.close() |
39 | cb(false) |
40 | }) |
41 | } |
42 |
Built with git-ssb-web