Files: a40d71e4d68bf04bb03d8040fbf7614880514dc8 / lib / app / sync / external-handler / git.js
915 bytesRaw
1 | const { shell } = require('electron') |
2 | const net = require('net') |
3 | |
4 | const externalViewer = 'https://git.scuttlebot.io' |
5 | const localViewer = 'http://localhost:7718' |
6 | |
7 | const gitMessageTypes = [ |
8 | 'git-repo', |
9 | 'git-update', |
10 | 'issue', |
11 | 'issue-edit', |
12 | 'pull-request' |
13 | ] |
14 | |
15 | module.exports = function (msg) { |
16 | if (!gitMessageTypes.includes(msg.value.content.type)) return |
17 | return function gitHandler (id) { |
18 | portInUse(7718, (useLocal) => { |
19 | shell.openExternal(`${useLocal ? localViewer : externalViewer}/${encodeURIComponent(id)}`) |
20 | }) |
21 | } |
22 | } |
23 | |
24 | function portInUse (port, cb) { |
25 | // super hacky check! |
26 | const server = net.createServer(function () {}) |
27 | server.listen(port, '127.0.0.1') |
28 | server.on('error', function () { |
29 | cb(true) // eslint-disable-line node/no-callback-literal |
30 | }) |
31 | server.on('listening', function () { |
32 | server.close() |
33 | cb(false) // eslint-disable-line node/no-callback-literal |
34 | }) |
35 | } |
36 |
Built with git-ssb-web