Commit b8b68a79bbf64f15810fd37ff36600b9d6e7d0e2
cleanup, sbot@12 and forked-systray@3
Henry committed on 9/13/2018, 5:44:05 PMParent: 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,67 @@ | |||
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 … | + const myName = curr[ssbConfig.keys.id]['name'][ssbConfig.keys.id] | ||
146 … | + if (myName instanceof Array && myName.length === 2) { // format is [ 'name', ts ] | ||
147 … | + console.log('updating menu with', myName[0]) | ||
148 … | + tray.emit('action', { | ||
149 … | + type: 'update-item', | ||
150 … | + seq_id: 0, | ||
151 … | + item: { | ||
152 … | + title: `@${myName[0]}`, | ||
153 … | + tooltip: ssbConfig.keys.id, | ||
154 … | + checked: false, | ||
155 … | + enabled: false | ||
156 … | + } | ||
157 … | + }) | ||
158 … | + } | ||
159 … | + }) | ||
160 … | + donecb(null) | ||
124 | 161 … | } | |
125 | 162 … | ||
126 | -function stop() { | ||
163 … | +function stop () { | ||
164 … | + // todo: sbot shutdown handler? | ||
127 | 165 … | tray.kill() | |
128 | 166 … | } | |
129 | 167 … | ||
130 | 168 … | const getConfig = () => { | |
169 … | + if (ssbConfig === null) { | ||
170 … | + return { type: 'error', msg: 'uninitialized config - call start() first' } | ||
171 … | + } | ||
131 | 172 … | 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 } | ||
173 … | + const k = ssbConfig.keys | ||
174 … | + const manifest = JSON.parse(fs.readFileSync(path.join(ssbConfig.path, 'manifest.json'))) | ||
175 … | + const remote = 'ws://localhost:8989~shs:' + k.id.substring(1, k.id.indexOf('.')) | ||
176 … | + return { | ||
177 … | + type: 'config', | ||
178 … | + keys: k, | ||
179 … | + manifest: manifest, | ||
180 … | + remote: remote | ||
181 … | + } | ||
137 | 182 … | } catch (n) { | |
138 | 183 … | return { type: 'error', msg: n.message } | |
139 | 184 … | } | |
140 | 185 … | } | |
141 | 186 … | ||
142 | 187 … | module.exports = { start, stop, getConfig } | |
143 | 188 … | ||
144 | 189 … | if (require.main === module) { | |
145 | - var errorLevel = start() | ||
146 | - console.log('exited with:', errorLevel) | ||
190 … | + start({}, (err) => { | ||
191 … | + if (err) console.error(err) | ||
192 … | + }) | ||
147 | 193 … | } |
Built with git-ssb-web