ftu/app.jsView |
---|
23 | 23 | exports.gives = nest('ftu.app') |
24 | 24 | |
25 | 25 | exports.needs = nest({ |
26 | 26 | 'styles.css': 'reduce', |
27 | | - 'translations.sync.strings': 'first', |
| 27 | + 'translations.sync.strings': 'first' |
28 | 28 | }) |
29 | 29 | |
30 | 30 | exports.create = (api) => { |
31 | 31 | return nest({ |
32 | | - 'ftu.app': function app() { |
33 | | - |
| 32 | + 'ftu.app': function app () { |
34 | 33 | const strings = api.translations.sync.strings() |
35 | 34 | |
36 | 35 | const css = values(api.styles.css()).join('\n') |
37 | 36 | insertCss(css) |
53 | 52 | |
54 | 53 | var importProcess = h('Page -ftu', [ |
55 | 54 | h('div.content', [ |
56 | 55 | h('h1', strings.backup.import.header), |
57 | | - h('p', [strings.backup.import.synchronizeMessage, state.currentSequence, '/', state.latestSequence]), |
| 56 | + h('p', [strings.backup.import.synchronizeMessage, state.currentSequence, '/', state.latestSequence]) |
58 | 57 | ]) |
59 | 58 | ]) |
60 | 59 | |
61 | 60 | |
65 | 64 | electron.ipcRenderer.send('import-completed') |
66 | 65 | } |
67 | 66 | }) |
68 | 67 | |
69 | | - if (fs.existsSync(path.join(configFolder, "secret"))) { |
| 68 | + if (fs.existsSync(path.join(configFolder, 'secret'))) { |
70 | 69 | |
71 | 70 | |
72 | 71 | console.log('resuming import') |
73 | 72 | let previousData = getImportData() |
102 | 101 | |
103 | 102 | observeSequence() |
104 | 103 | }) |
105 | 104 | |
106 | | - |
107 | | - |
108 | | -function actionCreateNewOne() { |
| 105 | +function actionCreateNewOne () { |
109 | 106 | isBusy.set(true) |
110 | | - const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, "../manifest.json"))) |
| 107 | + const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, '../manifest.json'))) |
111 | 108 | const manifestFile = path.join(configFolder, 'manifest.json') |
112 | 109 | if (!fs.existsSync(configFolder)) { |
113 | 110 | fs.mkdirSync(configFolder) |
114 | 111 | } |
115 | 112 | fs.writeFileSync(manifestFile, JSON.stringify(manifest)) |
116 | 113 | |
117 | | - |
118 | 114 | electron.ipcRenderer.send('create-new-identity') |
119 | 115 | } |
120 | 116 | |
121 | | -function actionImportIdentity(strings) { |
122 | | - const peersFile = path.join(configFolder, "gossip.json") |
123 | | - const secretFile = path.join(configFolder, "secret") |
124 | | - const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, "../manifest.json"))) |
| 117 | +function actionImportIdentity (strings) { |
| 118 | + const peersFile = path.join(configFolder, 'gossip.json') |
| 119 | + const secretFile = path.join(configFolder, 'secret') |
| 120 | + const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, '../manifest.json'))) |
125 | 121 | const manifestFile = path.join(configFolder, 'manifest.json') |
126 | 122 | |
127 | 123 | |
128 | 124 | dialog.showOpenDialog( |
132 | 128 | defaultPath: 'ticktack-identity.backup', |
133 | 129 | properties: ['openFile'] |
134 | 130 | }, |
135 | 131 | (filenames) => { |
136 | | - if (typeof filenames !== "undefined") { |
| 132 | + if (typeof filenames !== 'undefined') { |
137 | 133 | let filename = filenames[0] |
138 | 134 | let data = JSON.parse(fs.readFileSync(filename)) |
139 | | - if (data.hasOwnProperty("secret") && data.hasOwnProperty("peers") && data.hasOwnProperty("latestSequence")) { |
| 135 | + if (data.hasOwnProperty('secret') && data.hasOwnProperty('peers') && data.hasOwnProperty('latestSequence')) { |
140 | 136 | if (!fs.existsSync(configFolder)) { |
141 | 137 | fs.mkdirSync(configFolder) |
142 | 138 | } |
143 | 139 | |
144 | 140 | fs.writeFileSync(manifestFile, JSON.stringify(manifest)) |
145 | | - fs.writeFileSync(peersFile, JSON.stringify(data.peers), "utf8") |
146 | | - fs.writeFileSync(secretFile, data.secret, "utf8") |
| 141 | + fs.writeFileSync(peersFile, JSON.stringify(data.peers), 'utf8') |
| 142 | + fs.writeFileSync(secretFile, data.secret, 'utf8') |
147 | 143 | state.latestSequence.set(data.latestSequence) |
148 | 144 | state.currentSequence.set(0) |
149 | 145 | isPresentingOptions.set(false) |
150 | 146 | |
154 | 150 | setImportData(data) |
155 | 151 | |
156 | 152 | electron.ipcRenderer.send('import-identity') |
157 | 153 | } else { |
158 | | - console.log("> bad export file") |
| 154 | + console.log('> bad export file') |
159 | 155 | console.log(data) |
160 | | - alert("Bad Export File") |
| 156 | + alert('Bad Export File') |
161 | 157 | } |
162 | 158 | } |
163 | 159 | } |
164 | 160 | ) |
165 | 161 | } |
166 | 162 | |
167 | | -function windowControls() { |
| 163 | +function windowControls () { |
168 | 164 | if (process.platform === 'darwin') return |
169 | 165 | |
170 | 166 | const window = remote.getCurrentWindow() |
171 | 167 | const minimize = () => window.minimize() |
190 | 186 | }) |
191 | 187 | ]) |
192 | 188 | } |
193 | 189 | |
194 | | - |
195 | | -function assetPath(name) { |
| 190 | +function assetPath (name) { |
196 | 191 | return path.join(__dirname, '../assets', name) |
197 | 192 | } |
198 | 193 | |
199 | | - |
200 | | -function getImportData() { |
| 194 | +function getImportData () { |
201 | 195 | var importFile = path.join(configFolder, 'importing.json') |
202 | 196 | if (fs.existsSync(importFile)) { |
203 | 197 | let data = JSON.parse(fs.readFileSync(importFile)) |
204 | 198 | return data || false |
206 | 200 | return false |
207 | 201 | } |
208 | 202 | } |
209 | 203 | |
210 | | -function setImportData(data) { |
| 204 | +function setImportData (data) { |
211 | 205 | var importFile = path.join(configFolder, 'importing.json') |
212 | 206 | fs.writeFileSync(importFile, JSON.stringify(data)) |
213 | 207 | } |
214 | 208 | |
215 | | -function observeSequence() { |
| 209 | +function observeSequence () { |
216 | 210 | const pull = require('pull-stream') |
217 | 211 | const Client = require('ssb-client') |
218 | 212 | const config = require('../config').create().config.sync.load() |
219 | 213 | const _ = require('lodash') |
223 | 217 | console.error('problem starting client', err) |
224 | 218 | } else { |
225 | 219 | console.log('> sbot running!!!!') |
226 | 220 | |
| 221 | + ssbServer.gossip.peers((err, data) => { |
| 222 | + console.log('PEERS', err, data) |
| 223 | + |
| 224 | + data.forEach(peer => { |
| 225 | + ssbServer.gossip.connect({ |
| 226 | + 'host': peer.host, |
| 227 | + 'port': peer.port, |
| 228 | + 'key': peer.key |
| 229 | + }, function (err, v) { |
| 230 | + console.log('connected to ', peer.host) |
| 231 | + }) |
| 232 | + }) |
| 233 | + }) |
| 234 | + |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + function checkPeers () { |
| 261 | + ssbServer.ebt.peerStatus(ssbServer.id, (err, data) => { |
| 262 | + console.log('PEER STATUS:') |
| 263 | + console.log(data.seq) |
| 264 | + console.log(data.peers) |
| 265 | + console.log('-------') |
| 266 | + }) |
| 267 | + |
| 268 | + setTimeout(checkPeers, 5000) |
| 269 | + } |
| 270 | + |
227 | 271 | var feedSource = ssbServer.createUserStream({ |
228 | 272 | live: true, |
229 | 273 | id: ssbServer.id |
230 | 274 | }) |
231 | 275 | |
232 | 276 | var valueLogger = pull.drain((msg) => { |
233 | | - let seq = _.get(msg, "value.sequence", false) |
| 277 | + let seq = _.get(msg, 'value.sequence', false) |
234 | 278 | if (seq) { |
235 | 279 | state.currentSequence.set(seq) |
236 | 280 | } |
237 | 281 | }) |
238 | 282 | |
239 | 283 | pull( |
240 | 284 | feedSource, |
241 | | - valueLogger, |
| 285 | + valueLogger |
242 | 286 | ) |
243 | | - |
244 | 287 | } |
245 | 288 | }) |
246 | | -} |
| 289 | +} |