git ssb

10+

Matt McKegg / patchwork



Commit 5bc8a8f290ca35dec4add0a2960c251a539967f3

add further integration with local git-ssb

- automatically start `git-ssb web` if available and in path
- if `git-ssb web` is running, use that to open git links instead of
online viewer
Matt McKegg committed on 6/13/2017, 2:15:46 AM
Parent: b8225e707fd39a728ca23033e56f4d51d9c809ec

Files changed

modules/app/sync/external-handler/git.jschanged
server-process.jschanged
modules/app/sync/external-handler/git.jsView
@@ -1,10 +1,13 @@
11 const nest = require('depnest')
22 const {shell} = require('electron')
3 +const net = require('net')
34
45 exports.gives = nest('app.sync.externalHandler')
56
6-var viewer = 'http://git.scuttlebot.io'
7 +var externalViewer = 'http://git.scuttlebot.io'
8 +var localViewer = 'http://localhost:7718'
9 +
710 var gitMessageTypes = [
811 'git-repo',
912 'git-update',
1013 'issue',
@@ -15,8 +18,23 @@
1518 exports.create = (api) => {
1619 return nest('app.sync.externalHandler', function (msg) {
1720 if (!gitMessageTypes.includes(msg.value.content.type)) return
1821 return function gitHandler (id) {
19- shell.openExternal(`${viewer}/${encodeURIComponent(id)}`)
22 + portInUse(7718, (useLocal) => {
23 + shell.openExternal(`${useLocal ? localViewer : externalViewer}/${encodeURIComponent(id)}`)
24 + })
2025 }
2126 })
2227 }
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 +}
server-process.jsView
@@ -1,8 +1,9 @@
11 var serveBlobs = require('./lib/serve-blobs')
22 var fs = require('fs')
33 var Path = require('path')
44 var electron = require('electron')
5 +var spawn = require('child_process').spawn
56
67 var createSbot = require('scuttlebot')
78 .use(require('scuttlebot/plugins/master'))
89 .use(require('scuttlebot/plugins/gossip'))
@@ -27,5 +28,16 @@
2728 ssbConfig.manifest = context.sbot.getManifest()
2829 serveBlobs(context)
2930 fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest))
3031 electron.ipcRenderer.send('server-started', ssbConfig)
32 +
33 + // attempt to run git-ssb if it is installed and in path
34 + var gitSsb = spawn('git-ssb', [ 'web' ], {
35 + stdio: 'inherit'
36 + })
37 + gitSsb.on('error', () => {
38 + console.log('git-ssb is not installed, or not available in path')
39 + })
40 + process.on('exit', () => {
41 + gitSsb.kill()
42 + })
3143 }

Built with git-ssb-web