git ssb

1+

Daan Patchwork / patchwork



Tree: 000777db8b0f37f6c1d99fc608e4395c87512348

Files: 000777db8b0f37f6c1d99fc608e4395c87512348 / lib / app / sync / external-handler / git.js

915 bytesRaw
1const { shell } = require('electron')
2const net = require('net')
3
4const externalViewer = 'https://git.scuttlebot.io'
5const localViewer = 'http://localhost:7718'
6
7const gitMessageTypes = [
8 'git-repo',
9 'git-update',
10 'issue',
11 'issue-edit',
12 'pull-request'
13]
14
15module.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
24function 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