Skip to content

Commit 8c46c33

Browse files
committed
have server check for manifest before trying a connection
1 parent e2f5bb7 commit 8c46c33

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server.js

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

57
// Get config options from depject
68
const config = require('./config').create().config.sync.load()
7-
const startFrontend = () => electron.ipcRenderer.send('server-started')
89

9-
Client(config.keys, config, (err, server) => {
10-
if (err) { // no server currently running
11-
console.log('> scuttle-shell: starting')
12-
scuttleshell.start({}, (startErr) => {
13-
if (startErr) return console.error('> scuttle-shell: failed to start', startErr)
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)
1419

1520
startFrontend()
16-
})
17-
} else {
18-
console.log('> scuttle-shell / sbot already running')
19-
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)
2032

2133
startFrontend()
22-
}
23-
})
34+
})
35+
}
36+
37+
function startFrontend () {
38+
electron.ipcRenderer.send('server-started')
39+
}

0 commit comments

Comments
 (0)