git ssb

2+

mixmix / ticktack



Commit 1e55478903ee72a0823df4336254a2e7a9da5b0e

fix background-process for brand new installs

mix irving committed on 5/16/2018, 12:25:54 AM
Parent: 26d61ca780b49f14cec3dc071c03f71b4b3da905

Files changed

background-process.jschanged
background-process.jsView
@@ -23,19 +23,31 @@
2323 .use(require('ssb-ws'))
2424 .use(require('ssb-server-channel'))
2525 .use(require('./ssb-server-ticktack'))
2626
27-Client(config.keys, config, (err, ssbServer) => {
28- if (err) {
29- console.log('> starting sbot')
30- var sbot = createSbot(config)
27 +const manifestPath = Path.join(Path.join(config.path), 'manifest.json')
28 +const isNewInstall = !fs.existsSync(manifestPath)
3129
32- console.log(' > updating updating manifest.json')
33- var manifest = sbot.getManifest()
34- fs.writeFileSync(Path.join(config.path, 'manifest.json'), JSON.stringify(manifest))
35- electron.ipcRenderer.send('server-started')
36- } else {
37- console.log('> sbot running elsewhere')
38- electron.ipcRenderer.send('server-started')
39- // TODO send some warning to the client side
40- }
41-})
30 +if (isNewInstall) startSbot()
31 +else {
32 + // see if we can connect to an existing sbot on this config
33 + Client(config.keys, config, (err, server) => {
34 + // err implies no, we should start an sbot
35 + if (err) startSbot()
36 + else {
37 + // there's already and sbot running and we've connected to it
38 + console.log('> sbot running elsewhere')
39 + server.close() // close this client connection (app starts one of its own)
40 + electron.ipcRenderer.send('server-started')
41 + }
42 + })
43 +}
44 +
45 +function startSbot () {
46 + console.log('> starting sbot')
47 + var sbot = createSbot(config)
48 +
49 + console.log(' > updating updating manifest.json')
50 + var manifest = sbot.getManifest()
51 + fs.writeFileSync(manifestPath, JSON.stringify(manifest))
52 + electron.ipcRenderer.send('server-started')
53 +}

Built with git-ssb-web