git ssb

1+

mixmix / scuttle-shell



Commit 18d14f4199837cdee84531b77b1c5e083944bbc1

cleanup, sbot@12 and forked-systray@3

Henry committed on 9/17/2018, 7:50:18 AM
Parent: 2bccd6311eaa538c1dcb6a4d796fe73d159ea6ad

Files changed

package-lock.jsonchanged
package.jsonchanged
server.jschanged
package-lock.jsonView
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.jsonView
@@ -18,12 +18,12 @@
1818 },
1919 "dependencies": {
2020 "chrome-native-messaging": "^0.2.0",
2121 "ecstatic": "^3.1.0",
22- "forked-systray": "^2.0.0",
22 + "forked-systray": "^3.0.2",
2323 "minimist": "^1.2.0",
2424 "node-notifier": "^5.2.1",
25- "scuttlebot": "^11.4.2",
25 + "scuttlebot": "^12.0.1",
2626 "ssb-about": "^0.1.2",
2727 "ssb-backlinks": "^0.7.1",
2828 "ssb-blobs": "^1.1.4",
2929 "ssb-chess-db": "^1.0.3",
server.jsView
@@ -5,11 +5,18 @@
55 const ssbKeys = require('ssb-keys')
66 const minimist = require('minimist')
77 const notifier = require('node-notifier')
88 const SysTray = require('forked-systray').default
9-let tray = {}
109
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) }
1219 customConfig = customConfig || {}
1320 let appname = customConfig.appname || false
1421 let customPluginPaths = customConfig.plugins || false
1522 let argv = process.argv.slice(2)
@@ -21,11 +28,14 @@
2128 const config = require('ssb-config/inject')(ssbAppName, minimist(conf))
2229
2330 const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
2431 if (keys.curve === 'k256') {
32 + // i think this is _really_ old and could be removed
2533 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'))
2735 }
36 + config.keys = keys
37 + ssbConfig = config
2838
2939 const manifestFile = path.join(config.path, 'manifest.json')
3040
3141 const createSbot = require('scuttlebot')
@@ -70,11 +80,8 @@
7080 customPluginPaths.forEach(plugin => createSbot.use(require(plugin)))
7181 }
7282
7383 // start server
74-
75- config.keys = keys
76- console.log('config:', config)
7784 const server = createSbot(config)
7885
7986 // write RPC manifest to ~/.ssb/manifest.json
8087 fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2))
@@ -86,8 +93,13 @@
8693 title: 'Scuttle-Shell',
8794 tooltip: 'Secure Scuttlebutt',
8895 items: [
8996 {
97 + title: 'starting...',
98 + checked: false,
99 + enabled: true
100 + },
101 + {
90102 title: 'Quit',
91103 tooltip: 'Stop sbot and quit tray application',
92104 checked: false,
93105 enabled: true
@@ -97,12 +109,12 @@
97109 debug: false,
98110 copyDir: true
99111 })
100112
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':
105117 console.log('### EXITING IN TWO SECONDS ###')
106118
107119 notifier.notify({
108120 title: 'Secure Scuttlebutt',
@@ -115,33 +127,79 @@
115127 tray.kill()
116128 }
117129 })
118130
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)
121133 setTimeout(() =>
122134 process.exit(0), 2000)
123135 })
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)
124173 }
125174
126-function stop() {
175 +function stop () {
176 + // todo: sbot shutdown handler?
127177 tray.kill()
128178 }
129179
130180 const getConfig = () => {
181 + if (ssbConfig === null) {
182 + return { type: 'error', msg: 'uninitialized config - call start() first' }
183 + }
131184 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 + }
137194 } catch (n) {
138195 return { type: 'error', msg: n.message }
139196 }
140197 }
141198
142199 module.exports = { start, stop, getConfig }
143200
144201 if (require.main === module) {
145- var errorLevel = start()
146- console.log('exited with:', errorLevel)
202 + start({}, (err) => {
203 + if (err) console.error(err)
204 + })
147205 }

Built with git-ssb-web