|
1 | 1 | const electron = require('electron') |
| 2 | +const fs = require('fs') |
| 3 | +const { join } = require('path') |
2 | 4 | const Client = require('ssb-client') |
3 | 5 | const scuttleshell = require('scuttle-shell') |
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 | | -// 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) |
18 | 19 |
|
19 | 20 | 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) |
24 | 32 |
|
25 | 33 | startFrontend() |
26 | | - } |
27 | | -}) |
| 34 | + }) |
| 35 | +} |
| 36 | + |
| 37 | +function startFrontend () { |
| 38 | + electron.ipcRenderer.send('server-started') |
| 39 | +} |
0 commit comments