git ssb

1+

mixmix / scuttle-shell



Commit b8b68a79bbf64f15810fd37ff36600b9d6e7d0e2

cleanup, sbot@12 and forked-systray@3

Henry committed on 9/13/2018, 5:44:05 PM
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,67 @@
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 + 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)
124161 }
125162
126-function stop() {
163 +function stop () {
164 + // todo: sbot shutdown handler?
127165 tray.kill()
128166 }
129167
130168 const getConfig = () => {
169 + if (ssbConfig === null) {
170 + return { type: 'error', msg: 'uninitialized config - call start() first' }
171 + }
131172 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 + }
137182 } catch (n) {
138183 return { type: 'error', msg: n.message }
139184 }
140185 }
141186
142187 module.exports = { start, stop, getConfig }
143188
144189 if (require.main === module) {
145- var errorLevel = start()
146- console.log('exited with:', errorLevel)
190 + start({}, (err) => {
191 + if (err) console.error(err)
192 + })
147193 }

Built with git-ssb-web