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 viewerMatt McKegg committed on 6/13/2017, 2:15:46 AM
Parent: b8225e707fd39a728ca23033e56f4d51d9c809ec
Files changed
modules/app/sync/external-handler/git.js | changed |
server-process.js | changed |
modules/app/sync/external-handler/git.js | |||
---|---|---|---|
@@ -1,10 +1,13 @@ | |||
1 | 1 … | const nest = require('depnest') | |
2 | 2 … | const {shell} = require('electron') | |
3 … | +const net = require('net') | ||
3 | 4 … | ||
4 | 5 … | exports.gives = nest('app.sync.externalHandler') | |
5 | 6 … | ||
6 | -var viewer = 'http://git.scuttlebot.io' | ||
7 … | +var externalViewer = 'http://git.scuttlebot.io' | ||
8 … | +var localViewer = 'http://localhost:7718' | ||
9 … | + | ||
7 | 10 … | var gitMessageTypes = [ | |
8 | 11 … | 'git-repo', | |
9 | 12 … | 'git-update', | |
10 | 13 … | 'issue', | |
@@ -15,8 +18,23 @@ | |||
15 | 18 … | exports.create = (api) => { | |
16 | 19 … | return nest('app.sync.externalHandler', function (msg) { | |
17 | 20 … | if (!gitMessageTypes.includes(msg.value.content.type)) return | |
18 | 21 … | return function gitHandler (id) { | |
19 | - shell.openExternal(`${viewer}/${encodeURIComponent(id)}`) | ||
22 … | + portInUse(7718, (useLocal) => { | ||
23 … | + shell.openExternal(`${useLocal ? localViewer : externalViewer}/${encodeURIComponent(id)}`) | ||
24 … | + }) | ||
20 | 25 … | } | |
21 | 26 … | }) | |
22 | 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 … | +} |
server-process.js | ||
---|---|---|
@@ -1,8 +1,9 @@ | ||
1 | 1 … | var serveBlobs = require('./lib/serve-blobs') |
2 | 2 … | var fs = require('fs') |
3 | 3 … | var Path = require('path') |
4 | 4 … | var electron = require('electron') |
5 … | +var spawn = require('child_process').spawn | |
5 | 6 … | |
6 | 7 … | var createSbot = require('scuttlebot') |
7 | 8 … | .use(require('scuttlebot/plugins/master')) |
8 | 9 … | .use(require('scuttlebot/plugins/gossip')) |
@@ -27,5 +28,16 @@ | ||
27 | 28 … | ssbConfig.manifest = context.sbot.getManifest() |
28 | 29 … | serveBlobs(context) |
29 | 30 … | fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest)) |
30 | 31 … | 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 … | + }) | |
31 | 43 … | } |
Built with git-ssb-web