|
| 1 | +const fs = require('fs') |
| 2 | +const { join } = require('path') |
1 | 3 | const Client = require('ssb-client')
|
2 | 4 | const scuttleshell = require('scuttle-shell')
|
3 | 5 | const electron = require('electron')
|
4 | 6 |
|
5 | 7 | // Get config options from depject
|
6 | 8 | const config = require('./config').create().config.sync.load()
|
7 |
| -const startFrontend = () => electron.ipcRenderer.send('server-started') |
8 | 9 |
|
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) |
14 | 19 |
|
15 | 20 | 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) |
20 | 32 |
|
21 | 33 | startFrontend()
|
22 |
| - } |
23 |
| -}) |
| 34 | + }) |
| 35 | +} |
| 36 | + |
| 37 | +function startFrontend () { |
| 38 | + electron.ipcRenderer.send('server-started') |
| 39 | +} |
0 commit comments