Files: 59dd32b5a83df3b3e243a5bc34f33072e25a9701 / background-process.js
1757 bytesRaw
1 | const fs = require('fs') |
2 | const Path = require('path') |
3 | const electron = require('electron') |
4 | const Client = require('ssb-client') |
5 | |
6 | // pull config options out of depject |
7 | const config = require('./config').create().config.sync.load() |
8 | |
9 | var createSbot = require('scuttlebot') |
10 | .use(require('scuttlebot/plugins/master')) |
11 | .use(require('scuttlebot/plugins/gossip')) |
12 | .use(require('scuttlebot/plugins/replicate')) |
13 | .use(require('ssb-friends')) |
14 | .use(require('ssb-blobs')) |
15 | .use(require('ssb-backlinks')) |
16 | .use(require('ssb-private')) |
17 | .use(require('scuttlebot/plugins/invite')) |
18 | .use(require('scuttlebot/plugins/local')) |
19 | .use(require('scuttlebot/plugins/logging')) |
20 | .use(require('ssb-query')) |
21 | .use(require('ssb-about')) |
22 | .use(require('ssb-ebt')) |
23 | .use(require('ssb-ws')) |
24 | .use(require('ssb-server-channel')) |
25 | .use(require('./ssb-server-ticktack')) |
26 | |
27 | const manifestPath = Path.join(Path.join(config.path), 'manifest.json') |
28 | const isNewInstall = !fs.existsSync(manifestPath) |
29 | |
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 | } |
54 |
Built with git-ssb-web