Commit 18d14f4199837cdee84531b77b1c5e083944bbc1
cleanup, sbot@12 and forked-systray@3
Henry committed on 9/17/2018, 7:50:18 AMParent: 2bccd6311eaa538c1dcb6a4d796fe73d159ea6ad
Files changed
package-lock.json | changed |
package.json | changed |
server.js | changed |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 27188 bytes New file size: 178475 bytes |
package.json | ||
---|---|---|
@@ -18,12 +18,12 @@ | ||
18 | 18 … | }, |
19 | 19 … | "dependencies": { |
20 | 20 … | "chrome-native-messaging": "^0.2.0", |
21 | 21 … | "ecstatic": "^3.1.0", |
22 | - "forked-systray": "^2.0.0", | |
22 … | + "forked-systray": "^3.0.2", | |
23 | 23 … | "minimist": "^1.2.0", |
24 | 24 … | "node-notifier": "^5.2.1", |
25 | - "scuttlebot": "^11.4.2", | |
25 … | + "scuttlebot": "^12.0.1", | |
26 | 26 … | "ssb-about": "^0.1.2", |
27 | 27 … | "ssb-backlinks": "^0.7.1", |
28 | 28 … | "ssb-blobs": "^1.1.4", |
29 | 29 … | "ssb-chess-db": "^1.0.3", |
server.js | ||
---|---|---|
@@ -5,11 +5,18 @@ | ||
5 | 5 … | const ssbKeys = require('ssb-keys') |
6 | 6 … | const minimist = require('minimist') |
7 | 7 … | const notifier = require('node-notifier') |
8 | 8 … | const SysTray = require('forked-systray').default |
9 | -let tray = {} | |
10 | 9 … | |
11 | -function start(customConfig) { | |
10 … | +// uninitialized | |
11 … | +let tray = null | |
12 … | +let ssbConfig = null | |
13 … | + | |
14 … | +function noop () {} | |
15 … | + | |
16 … | +function start (customConfig, donecb) { | |
17 … | + donecb = donecb || noop | |
18 … | + // TODO: try { allthethings } catch(e) { donecb(e) } | |
12 | 19 … | customConfig = customConfig || {} |
13 | 20 … | let appname = customConfig.appname || false |
14 | 21 … | let customPluginPaths = customConfig.plugins || false |
15 | 22 … | let argv = process.argv.slice(2) |
@@ -21,11 +28,14 @@ | ||
21 | 28 … | const config = require('ssb-config/inject')(ssbAppName, minimist(conf)) |
22 | 29 … | |
23 | 30 … | const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret')) |
24 | 31 … | if (keys.curve === 'k256') { |
32 … | + // i think this is _really_ old and could be removed | |
25 | 33 … | throw new Error('k256 curves are no longer supported,' + |
26 | - 'please delete' + path.join(config.path, 'secret')) | |
34 … | + 'please delete' + path.join(config.path, 'secret')) | |
27 | 35 … | } |
36 … | + config.keys = keys | |
37 … | + ssbConfig = config | |
28 | 38 … | |
29 | 39 … | const manifestFile = path.join(config.path, 'manifest.json') |
30 | 40 … | |
31 | 41 … | const createSbot = require('scuttlebot') |
@@ -70,11 +80,8 @@ | ||
70 | 80 … | customPluginPaths.forEach(plugin => createSbot.use(require(plugin))) |
71 | 81 … | } |
72 | 82 … | |
73 | 83 … | // start server |
74 | - | |
75 | - config.keys = keys | |
76 | - console.log('config:', config) | |
77 | 84 … | const server = createSbot(config) |
78 | 85 … | |
79 | 86 … | // write RPC manifest to ~/.ssb/manifest.json |
80 | 87 … | fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2)) |
@@ -86,8 +93,13 @@ | ||
86 | 93 … | title: 'Scuttle-Shell', |
87 | 94 … | tooltip: 'Secure Scuttlebutt', |
88 | 95 … | items: [ |
89 | 96 … | { |
97 … | + title: 'starting...', | |
98 … | + checked: false, | |
99 … | + enabled: true | |
100 … | + }, | |
101 … | + { | |
90 | 102 … | title: 'Quit', |
91 | 103 … | tooltip: 'Stop sbot and quit tray application', |
92 | 104 … | checked: false, |
93 | 105 … | enabled: true |
@@ -97,12 +109,12 @@ | ||
97 | 109 … | debug: false, |
98 | 110 … | copyDir: true |
99 | 111 … | }) |
100 | 112 … | |
101 | - tray.onClick(action => { | |
102 | - console.log('got action:', action) | |
103 | - switch (action.seq_id) { | |
104 | - case 0: | |
113 … | + tray.on('click', (action) => { | |
114 … | + console.log('scuttle-shell got action:', action) | |
115 … | + switch (action.item.title) { | |
116 … | + case 'Quit': | |
105 | 117 … | console.log('### EXITING IN TWO SECONDS ###') |
106 | 118 … | |
107 | 119 … | notifier.notify({ |
108 | 120 … | title: 'Secure Scuttlebutt', |
@@ -115,33 +127,79 @@ | ||
115 | 127 … | tray.kill() |
116 | 128 … | } |
117 | 129 … | }) |
118 | 130 … | |
119 | - tray.onExit((code, signal) => { | |
120 | - console.log('got exit:', code) | |
131 … | + tray.on('exit', (code, signal) => { | |
132 … | + console.log('scuttle-shell got exit:', code) | |
121 | 133 … | setTimeout(() => |
122 | 134 … | process.exit(0), 2000) |
123 | 135 … | }) |
136 … | + | |
137 … | + const sbotVersion = server.version() | |
138 … | + console.log(`started sbot server v${sbotVersion}`) | |
139 … | + | |
140 … | + server.about.get((err, curr) => { | |
141 … | + if (err) { | |
142 … | + console.warn('got err from about idx:', err) | |
143 … | + return | |
144 … | + } | |
145 … | + // new key maybe? might not have set a name yet | |
146 … | + if (typeof curr === 'undefined') { | |
147 … | + return | |
148 … | + } | |
149 … | + const myAbouts = curr[ssbConfig.keys.id] | |
150 … | + if (typeof myAbouts === 'undefined') { | |
151 … | + return | |
152 … | + } | |
153 … | + const myNames = myAbouts['name'] | |
154 … | + if (typeof myNames === 'undefined') { | |
155 … | + return | |
156 … | + } | |
157 … | + const fromMe = myNames[ssbConfig.keys.id] | |
158 … | + if (fromMe instanceof Array && fromMe.length === 2) { // format is [ 'name', ts ] | |
159 … | + console.log('updating menu with', fromMe[0]) | |
160 … | + tray.emit('action', { | |
161 … | + type: 'update-item', | |
162 … | + seq_id: 0, | |
163 … | + item: { | |
164 … | + title: `@${myName[0]}`, | |
165 … | + tooltip: ssbConfig.keys.id, | |
166 … | + checked: false, | |
167 … | + enabled: false | |
168 … | + } | |
169 … | + }) | |
170 … | + } | |
171 … | + }) | |
172 … | + donecb(null) | |
124 | 173 … | } |
125 | 174 … | |
126 | -function stop() { | |
175 … | +function stop () { | |
176 … | + // todo: sbot shutdown handler? | |
127 | 177 … | tray.kill() |
128 | 178 … | } |
129 | 179 … | |
130 | 180 … | const getConfig = () => { |
181 … | + if (ssbConfig === null) { | |
182 … | + return { type: 'error', msg: 'uninitialized config - call start() first' } | |
183 … | + } | |
131 | 184 … | try { |
132 | - let secret = fs.readFileSync(pathToSecret, 'utf8') | |
133 | - let keys = JSON.parse(secret.replace(/#[^\n]*/g, '')) | |
134 | - let manifest = JSON.parse(fs.readFileSync(path.join(config.path, 'manifest.json'))) | |
135 | - let remote = 'ws://localhost:8989~shs:' + keys.id.substring(1, keys.id.indexOf('.')) | |
136 | - return { type: 'config', keys: keys, manifest: manifest, remote: remote, secret: secret } | |
185 … | + const k = ssbConfig.keys | |
186 … | + const manifest = JSON.parse(fs.readFileSync(path.join(ssbConfig.path, 'manifest.json'))) | |
187 … | + const remote = 'ws://localhost:8989~shs:' + k.id.substring(1, k.id.indexOf('.')) | |
188 … | + return { | |
189 … | + type: 'config', | |
190 … | + keys: k, | |
191 … | + manifest: manifest, | |
192 … | + remote: remote | |
193 … | + } | |
137 | 194 … | } catch (n) { |
138 | 195 … | return { type: 'error', msg: n.message } |
139 | 196 … | } |
140 | 197 … | } |
141 | 198 … | |
142 | 199 … | module.exports = { start, stop, getConfig } |
143 | 200 … | |
144 | 201 … | if (require.main === module) { |
145 | - var errorLevel = start() | |
146 | - console.log('exited with:', errorLevel) | |
202 … | + start({}, (err) => { | |
203 … | + if (err) console.error(err) | |
204 … | + }) | |
147 | 205 … | } |
Built with git-ssb-web