Files: de92553986e36c8aa555fb0a529a98913b109777 / server.js
2463 bytesRaw
1 | |
2 | |
3 | const http = require('http') |
4 | const serve = require('ecstatic') |
5 | const fs = require('fs') |
6 | const path = require('path') |
7 | const ssbKeys = require('ssb-keys') |
8 | const minimist = require('minimist') |
9 | const notifier = require('node-notifier') |
10 | const SysTray = require('systray').default |
11 | |
12 | let argv = process.argv.slice(2) |
13 | let i = argv.indexOf('--') |
14 | let conf = argv.slice(i + 1) |
15 | argv = ~i ? argv.slice(0, i) : argv |
16 | |
17 | const config = require('ssb-config/inject')(process.env.ssb_appname, minimist(conf)) |
18 | |
19 | const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret')) |
20 | if (keys.curve === 'k256') { |
21 | throw new Error('k256 curves are no longer supported,' + |
22 | 'please delete' + path.join(config.path, 'secret')) |
23 | } |
24 | |
25 | const manifestFile = path.join(config.path, 'manifest.json') |
26 | |
27 | const createSbot = require('scuttlebot') |
28 | // .use(require('scuttlebot/plugins/plugins')) |
29 | .use(require('scuttlebot/plugins/master')) |
30 | .use(require('scuttlebot/plugins/gossip')) |
31 | .use(require('scuttlebot/plugins/replicate')) |
32 | .use(require('ssb-friends')) |
33 | .use(require('ssb-blobs')) |
34 | .use(require('scuttlebot/plugins/invite')) |
35 | .use(require('scuttlebot/plugins/local')) |
36 | .use(require('ssb-query')) |
37 | .use(require('ssb-ooo')) |
38 | .use(require('ssb-ebt')) |
39 | .use(require('ssb-ws')) |
40 | .use(require('ssb-names')) |
41 | .use(require('ssb-backlinks')) |
42 | .use(require('ssb-about')) |
43 | |
44 | // start server |
45 | |
46 | config.keys = keys |
47 | const server = createSbot(config) |
48 | |
49 | // write RPC manifest to ~/.ssb/manifest.json |
50 | fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2)) |
51 | |
52 | const icon = fs.readFileSync(path.join(__dirname, `icon.${process.platform === 'win32' ? 'ico' : 'png'}`)) |
53 | const tray = new SysTray({ |
54 | menu: { |
55 | icon: icon.toString('base64'), |
56 | title: 'Scuttle-Shell', |
57 | tooltip: 'Secure Scuttlebutt tray app', |
58 | items: [ |
59 | |
60 | { |
61 | title: 'Quit', |
62 | tooltip: 'Stop sbot and quit tray application', |
63 | checked: false, |
64 | enabled: true |
65 | } |
66 | ] |
67 | }, |
68 | debug: false, |
69 | copyDir: true, |
70 | }) |
71 | |
72 | tray.onClick(action => { |
73 | switch (action.seq_id) { |
74 | case 0: |
75 | console.log("### EXITING IN TWO SECONDS ###") |
76 | |
77 | notifier.notify({ |
78 | title: 'Secure Scuttlebutt', |
79 | message: `Secure Scuttlebutt will exit in two seconds...`, |
80 | icon: path.join(__dirname, "icon.png"), |
81 | wait: true, |
82 | id: 0, |
83 | }) |
84 | |
85 | tray.kill() |
86 | } |
87 | }) |
88 | |
89 | tray.onExit((code, signal) => { |
90 | setTimeout(() => |
91 | process.exit(0), 2000) |
92 | }) |
Built with git-ssb-web