Files: 8f4b44fd5c96edb542eb7ebe86e16d6807a5abc5 / modules / app / sync / external-handler / git.js
986 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, 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