Skip to content

Commit

Permalink
have server check for manifest before trying a connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Nov 8, 2018
1 parent e2f5bb7 commit 8c46c33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 28 additions & 12 deletions server.js
@@ -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')
}

0 comments on commit 8c46c33

Please sign in to comment.