git ssb

16+

Dominic / patchbay



Commit bf1c0487e7a3cc6ff42c236b70370491e557e10f

app receives config from externally - ssb-ahoy

mixmix committed on 5/9/2019, 1:51:29 AM
Parent: a9a7ed91550f0d144e2ffba40c39a02b57fca8da

Files changed

app/html/app.jschanged
app/sync/go-to.jschanged
app/sync/initialise/electron-context-menu-and-spellcheck.jschanged
app/sync/start.jsadded
exports.jschanged
index.jschanged
package.jsonchanged
ui.jschanged
config.jsdeleted
app/html/app.jsView
@@ -4,32 +4,16 @@
44 exports.gives = nest('app.html.app')
55
66 exports.needs = nest({
77 'app.html.tabs': 'first',
8- 'app.page.errors': 'first',
9- 'app.sync.goTo': 'first',
10- 'app.sync.initialise': 'first',
11- 'history.obs.location': 'first',
12- 'history.sync.push': 'first',
138 'settings.sync.get': 'first'
149 })
1510
1611 exports.create = function (api) {
1712 return nest('app.html.app', app)
1813
1914 function app (initialTabs) {
20- console.log('STARTING app')
21-
22- const App = h('App', api.app.html.tabs({
15+ return h('App', api.app.html.tabs({
2316 initial: initialTabs || api.settings.sync.get('patchbay.defaultTabs')
2417 }))
25-
26- api.app.sync.initialise(App)
27- // runs all the functions in app/sync/initialise
28-
29- api.history.obs.location()(loc => {
30- api.app.sync.goTo(loc || {})
31- })
32-
33- return App
3418 }
3519 }
app/sync/go-to.jsView
@@ -22,8 +22,9 @@
2222 // - extracts scrollToMessage into app.page.thread
2323 // - router.sync.router would take (location, { position }) ?
2424
2525 function goTo (location, options = {}) {
26+ if (!location) return
2627 const {
2728 openBackground = false,
2829 split = false
2930 } = options
app/sync/initialise/electron-context-menu-and-spellcheck.jsView
@@ -9,16 +9,15 @@
99 exports.gives = nest('app.sync.initialise')
1010
1111 exports.needs = nest({
1212 'app.sync.goTo': 'first',
13- 'config.sync.load': 'first',
1413 'sbot.async.get': 'first',
1514 'settings.sync.get': 'first'
1615 })
1716
1817 exports.create = function (api) {
19- return nest('app.sync.initialise', function () {
20- const { gateway } = api.config.sync.load()
18+ return nest('app.sync.initialise', function (_, _config) {
19+ const { gateway } = _config
2120
2221 const config = {
2322 gateway: gateway || 'https://viewer.scuttlebot.io',
2423 localeCode: api.settings.sync.get('patchbay.localeCode') || 'en-GB'
app/sync/start.jsView
@@ -1,0 +1,48 @@
1+const nest = require('depnest')
2+
3+exports.gives = nest({
4+ 'app.sync.start': true,
5+ 'config.sync.load': true // used by patchcore
6+})
7+
8+exports.needs = nest({
9+ 'app.html.app': 'first',
10+ 'app.page.errors': 'first',
11+ 'app.sync.goTo': 'first',
12+ 'app.sync.initialise': 'first',
13+ 'history.obs.location': 'first',
14+ 'history.sync.push': 'first',
15+ 'settings.sync.get': 'first'
16+})
17+
18+exports.create = function (api) {
19+ var _config
20+ return nest({
21+ 'app.sync.start': start,
22+ 'config.sync.load': config
23+ })
24+
25+ function start (config, opts = {}) {
26+ console.log('STARTING Patchbay UI')
27+
28+ _config = config
29+ localStorage.patchbayConfig = null
30+
31+ const App = api.app.html.app(opts.initialTabs)
32+
33+ api.app.sync.initialise(App, config)
34+ // runs all the functions in app/sync/initialise
35+
36+ api.history.obs.location()(api.app.sync.goTo)
37+
38+ document.body.appendChild(App)
39+ return App
40+ }
41+
42+ function config () {
43+ console.log('getting called!!!')
44+ return _config || JSON.parse(localStorage.patchbayConfig)
45+ // HACK - there's a depject race condition where config.sync.load is being called
46+ // before app.sync.start is called!
47+ }
48+}
exports.jsView
@@ -15,9 +15,8 @@
1515 router: bulk(__dirname, [ 'router/**/*.js' ]),
1616 styles: bulk(__dirname, [ 'styles/**/*.js' ]),
1717 sbot: bulk(__dirname, [ 'sbot/**/*.js' ]),
1818
19- config: require('./config'), // shouldn't be in here ?
2019 suggestions: require('patch-suggest'),
2120 settings: require('patch-settings'),
2221 drafts: require('patch-drafts'),
2322 history: require('patch-history')
index.jsView
@@ -1,16 +1,14 @@
11 const ahoy = require('ssb-ahoy')
22 const StartMenus = require('./menu')
33
4-const config = require('./config').create().config.sync.load()
5-
64 const plugins = [
75 'ssb-server/plugins/master',
8- 'ssb-server/plugins/logging',
96 'ssb-server/plugins/unix-socket',
107 'ssb-server/plugins/no-auth',
118 'ssb-server/plugins/onion',
129 'ssb-server/plugins/local',
10+ 'ssb-server/plugins/logging',
1311
1412 'ssb-legacy-conn',
1513 'ssb-replicate',
1614 'ssb-friends',
@@ -34,11 +32,10 @@
3432
3533 ahoy(
3634 {
3735 title: 'Patchbay',
38- config,
3936 plugins,
40- // appDir: '../patchbay', // uncomment when ssb-ahoy is symlinked in!
37+ appDir: '../patchbay', // uncomment when ssb-ahoy is symlinked in!
4138 uiPath: './ui.js'
4239 },
4340 (state) => {
4441 StartMenus(state)
package.jsonView
@@ -96,9 +96,8 @@
9696 "ssb-blob-files": "^1.1.3",
9797 "ssb-blobs": "^1.1.12",
9898 "ssb-chess-db": "^1.0.6",
9999 "ssb-chess-mithril": "1.0.10",
100- "ssb-config": "^3.2.3",
101100 "ssb-ebt": "^5.5.2",
102101 "ssb-friend-pub": "^1.0.5",
103102 "ssb-friends": "^3.1.12",
104103 "ssb-invite": "^2.0.3",
ui.jsView
@@ -5,8 +5,11 @@
55
66 const { patchcore, patchbay, plugins } = require('./exports')
77
88 function Start (config = {}) {
9+ localStorage.patchbayConfig = JSON.stringify(config)
10+ // HACK to get config accessible D:
11+
912 // polyfills
1013 require('setimmediate')
1114
1215 const sockets = combine(
@@ -15,9 +18,9 @@
1518 patchcore
1619 )
1720 // plugins loaded first will over-ride core modules loaded later
1821
19- const api = entry(sockets, nest('app.html.app', 'first'))
20- document.body.appendChild(api.app.html.app())
22+ const api = entry(sockets, nest('app.sync.start', 'first'))
23+ api.app.sync.start(config)
2124 }
2225
2326 module.exports = Start
config.jsView
@@ -1,90 +1,0 @@
1-const nest = require('depnest')
2-const Config = require('ssb-config/inject')
3-const Path = require('path')
4-const merge = require('lodash/merge')
5-// settings not available in api yet, so we need to load it manually
6-const settings = require('patch-settings').patchSettings
7-
8-exports.gives = nest('config.sync.load')
9-exports.create = (api) => {
10- var config
11- return nest('config.sync.load', () => {
12- if (config) return config
13-
14- console.log('LOADING config')
15- config = Config(process.env.ssb_appname || 'ssb', {
16- // friends: { hops: 2 }
17- })
18-
19- config = addSockets(config)
20- config = fixLocalhost(config)
21-
22- try {
23- window
24- // HACK (mix): patch-settings currently uses localStorage as persistence
25- // this means trying to load config outside context of electron crashes app ):
26- config = pubHopSettings(config)
27- config = torOnly(config)
28- } catch (e) {
29- console.log('TODO: decouple patchbay config from localStorage')
30- }
31-
32- return config
33- })
34-}
35-
36-function addSockets (config) {
37- if (process.platform === 'win32') return config
38-
39- const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '')
40- return merge(
41- config,
42- {
43- connections: {
44- incoming: { unix: [{ scope: 'device', transform: 'noauth', server: true }] }
45- },
46- remote: `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` // overwrites
47- }
48- )
49-}
50-
51-function fixLocalhost (config) {
52- if (process.platform !== 'win32') return config
53-
54- // without this host defaults to :: which doesn't work on windows 10?
55- config.connections.incoming.net[0].host = '127.0.0.1'
56- config.connections.incoming.ws[0].host = '127.0.0.1'
57- config.host = '127.0.0.1'
58- return config
59-}
60-
61-function pubHopSettings (config) {
62- const pubHopAll = 3
63- let pubHopConnections = settings.create().settings.sync.get('patchbay.pubHopConnections', pubHopAll)
64- if (pubHopConnections === pubHopAll) return config
65-
66- return merge(
67- config,
68- {
69- friendPub: { hops: pubHopConnections },
70- gossip: {
71- friends: true,
72- global: false
73- }
74- })
75-}
76-
77-function torOnly (config) {
78- if (settings.create().settings.sync.get('patchbay.torOnly', false)) {
79- config = merge(config, {
80- connections: {
81- outgoing: {
82- 'onion': [{ 'transform': 'shs' }]
83- }
84- }
85- })
86-
87- delete config.connections.outgoing.net
88- return config
89- } else { return config }
90-}

Built with git-ssb-web