-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
have server check for manifest before trying a connection
- Loading branch information
Showing
2 changed files
with
30 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
const fs = require('fs') | ||
const { join } = require('path') | ||
const Client = require('ssb-client') | ||
const scuttleshell = require('scuttle-shell') | ||
const electron = require('electron') | ||
|
||
// Get config options from depject | ||
const config = require('./config').create().config.sync.load() | ||
const startFrontend = () => electron.ipcRenderer.send('server-started') | ||
|
||
Client(config.keys, config, (err, server) => { | ||
if (err) { // no server currently running | ||
console.log('> scuttle-shell: starting') | ||
scuttleshell.start({}, (startErr) => { | ||
if (startErr) return console.error('> scuttle-shell: failed to start', startErr) | ||
// check if manifest.json exists (has any sbot ever started?) | ||
if (!fs.existsSync(join(config.path, 'manifest.json'))) startScuttleShell() | ||
else { | ||
// check if there's a server running we can connect to | ||
Client(config.keys, config, (err, server) => { | ||
if (err) startScuttleShell() | ||
else { | ||
console.log('> scuttle-shell / sbot already running') | ||
server.close() // close this connection (app starts one of its own) | ||
|
||
startFrontend() | ||
}) | ||
} else { | ||
console.log('> scuttle-shell / sbot already running') | ||
server.close() // close this connection (app starts one of its own) | ||
} | ||
}) | ||
} | ||
|
||
// helpers | ||
|
||
function startScuttleShell () { | ||
console.log('> scuttle-shell: starting') | ||
|
||
scuttleshell.start({}, (startErr) => { | ||
if (startErr) return console.error('> scuttle-shell: failed to start', startErr) | ||
|
||
startFrontend() | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
function startFrontend () { | ||
electron.ipcRenderer.send('server-started') | ||
} |