Skip to content

Commit 3310050

Browse files
mixmixcryptix
authored andcommitted
have server check for manifest before trying a connection
1 parent aedbc0b commit 3310050

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

server.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
const electron = require('electron')
2+
const fs = require('fs')
3+
const { join } = require('path')
24
const Client = require('ssb-client')
35
const scuttleshell = require('scuttle-shell')
46

57
// Get config options from depject
68
const config = require('./config').create().config.sync.load()
7-
const startFrontend = () => electron.ipcRenderer.send('server-started')
8-
9-
// Check if scuttle-shell is already running
10-
// TODO - make this check for scuttle-shell specifically (and not just an sbot)
11-
Client(config.keys, config, (err, server) => {
12-
// err implies no server currently running
13-
if (err) {
14-
console.warn('client connection failed:', err)
15-
console.log('> starting scuttle-shell')
16-
scuttleshell.start({}, (startErr) => {
17-
if (startErr) return console.error('> scuttle-shell: failed to start', startErr)
9+
10+
// check if manifest.json exists (has any sbot ever started?)
11+
if (!fs.existsSync(join(config.path, 'manifest.json'))) startScuttleShell()
12+
else {
13+
// check if there's a server running we can connect to
14+
Client(config.keys, config, (err, server) => {
15+
if (err) startScuttleShell()
16+
else {
17+
console.log('> scuttle-shell / sbot already running')
18+
server.close() // close this connection (app starts one of its own)
1819

1920
startFrontend()
20-
})
21-
} else {
22-
console.log('> scuttle-shell / sbot already running')
23-
server.close() // close this connection (app starts one of its own)
21+
}
22+
})
23+
}
24+
25+
// helpers
26+
27+
function startScuttleShell () {
28+
console.log('> scuttle-shell: starting')
29+
30+
scuttleshell.start({}, (startErr) => {
31+
if (startErr) return console.error('> scuttle-shell: failed to start', startErr)
2432

2533
startFrontend()
26-
}
27-
})
34+
})
35+
}
36+
37+
function startFrontend () {
38+
electron.ipcRenderer.send('server-started')
39+
}

0 commit comments

Comments
 (0)