Commit bf1c0487e7a3cc6ff42c236b70370491e557e10f
app receives config from externally - ssb-ahoy
mixmix committed on 5/9/2019, 1:51:29 AMParent: a9a7ed91550f0d144e2ffba40c39a02b57fca8da
Files changed
app/html/app.js | changed |
app/sync/go-to.js | changed |
app/sync/initialise/electron-context-menu-and-spellcheck.js | changed |
app/sync/start.js | added |
exports.js | changed |
index.js | changed |
package.json | changed |
ui.js | changed |
config.js | deleted |
app/html/app.js | ||
---|---|---|
@@ -4,32 +4,16 @@ | ||
4 | 4 | exports.gives = nest('app.html.app') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | 7 | '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', | |
13 | 8 | 'settings.sync.get': 'first' |
14 | 9 | }) |
15 | 10 | |
16 | 11 | exports.create = function (api) { |
17 | 12 | return nest('app.html.app', app) |
18 | 13 | |
19 | 14 | 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({ | |
23 | 16 | initial: initialTabs || api.settings.sync.get('patchbay.defaultTabs') |
24 | 17 | })) |
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 | |
34 | 18 | } |
35 | 19 | } |
app/sync/go-to.js | ||
---|---|---|
@@ -22,8 +22,9 @@ | ||
22 | 22 | // - extracts scrollToMessage into app.page.thread |
23 | 23 | // - router.sync.router would take (location, { position }) ? |
24 | 24 | |
25 | 25 | function goTo (location, options = {}) { |
26 | + if (!location) return | |
26 | 27 | const { |
27 | 28 | openBackground = false, |
28 | 29 | split = false |
29 | 30 | } = options |
app/sync/initialise/electron-context-menu-and-spellcheck.js | ||
---|---|---|
@@ -9,16 +9,15 @@ | ||
9 | 9 | exports.gives = nest('app.sync.initialise') |
10 | 10 | |
11 | 11 | exports.needs = nest({ |
12 | 12 | 'app.sync.goTo': 'first', |
13 | - 'config.sync.load': 'first', | |
14 | 13 | 'sbot.async.get': 'first', |
15 | 14 | 'settings.sync.get': 'first' |
16 | 15 | }) |
17 | 16 | |
18 | 17 | 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 | |
21 | 20 | |
22 | 21 | const config = { |
23 | 22 | gateway: gateway || 'https://viewer.scuttlebot.io', |
24 | 23 | localeCode: api.settings.sync.get('patchbay.localeCode') || 'en-GB' |
app/sync/start.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -15,9 +15,8 @@ | ||
15 | 15 | router: bulk(__dirname, [ 'router/**/*.js' ]), |
16 | 16 | styles: bulk(__dirname, [ 'styles/**/*.js' ]), |
17 | 17 | sbot: bulk(__dirname, [ 'sbot/**/*.js' ]), |
18 | 18 | |
19 | - config: require('./config'), // shouldn't be in here ? | |
20 | 19 | suggestions: require('patch-suggest'), |
21 | 20 | settings: require('patch-settings'), |
22 | 21 | drafts: require('patch-drafts'), |
23 | 22 | history: require('patch-history') |
index.js | ||
---|---|---|
@@ -1,16 +1,14 @@ | ||
1 | 1 | const ahoy = require('ssb-ahoy') |
2 | 2 | const StartMenus = require('./menu') |
3 | 3 | |
4 | -const config = require('./config').create().config.sync.load() | |
5 | - | |
6 | 4 | const plugins = [ |
7 | 5 | 'ssb-server/plugins/master', |
8 | - 'ssb-server/plugins/logging', | |
9 | 6 | 'ssb-server/plugins/unix-socket', |
10 | 7 | 'ssb-server/plugins/no-auth', |
11 | 8 | 'ssb-server/plugins/onion', |
12 | 9 | 'ssb-server/plugins/local', |
10 | + 'ssb-server/plugins/logging', | |
13 | 11 | |
14 | 12 | 'ssb-legacy-conn', |
15 | 13 | 'ssb-replicate', |
16 | 14 | 'ssb-friends', |
@@ -34,11 +32,10 @@ | ||
34 | 32 | |
35 | 33 | ahoy( |
36 | 34 | { |
37 | 35 | title: 'Patchbay', |
38 | - config, | |
39 | 36 | plugins, |
40 | - // appDir: '../patchbay', // uncomment when ssb-ahoy is symlinked in! | |
37 | + appDir: '../patchbay', // uncomment when ssb-ahoy is symlinked in! | |
41 | 38 | uiPath: './ui.js' |
42 | 39 | }, |
43 | 40 | (state) => { |
44 | 41 | StartMenus(state) |
package.json | ||
---|---|---|
@@ -96,9 +96,8 @@ | ||
96 | 96 | "ssb-blob-files": "^1.1.3", |
97 | 97 | "ssb-blobs": "^1.1.12", |
98 | 98 | "ssb-chess-db": "^1.0.6", |
99 | 99 | "ssb-chess-mithril": "1.0.10", |
100 | - "ssb-config": "^3.2.3", | |
101 | 100 | "ssb-ebt": "^5.5.2", |
102 | 101 | "ssb-friend-pub": "^1.0.5", |
103 | 102 | "ssb-friends": "^3.1.12", |
104 | 103 | "ssb-invite": "^2.0.3", |
ui.js | ||
---|---|---|
@@ -5,8 +5,11 @@ | ||
5 | 5 | |
6 | 6 | const { patchcore, patchbay, plugins } = require('./exports') |
7 | 7 | |
8 | 8 | function Start (config = {}) { |
9 | + localStorage.patchbayConfig = JSON.stringify(config) | |
10 | + // HACK to get config accessible D: | |
11 | + | |
9 | 12 | // polyfills |
10 | 13 | require('setimmediate') |
11 | 14 | |
12 | 15 | const sockets = combine( |
@@ -15,9 +18,9 @@ | ||
15 | 18 | patchcore |
16 | 19 | ) |
17 | 20 | // plugins loaded first will over-ride core modules loaded later |
18 | 21 | |
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) | |
21 | 24 | } |
22 | 25 | |
23 | 26 | module.exports = Start |
config.js | ||
---|---|---|
@@ -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