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