Commit a20d5059cc43f723aefd7fe6e3a79aa751ded3a9
extract startup code into initialise functions. so tidy!
mix irving committed on 2/17/2018, 6:45:25 AMParent: d8266c2ee656afa2eaf8d2526a54ffa339e2b8ec
Files changed
app/html/app.js | changed |
app/sync/initialise/electronState.js | added |
app/sync/initialise/errorCatcher.js | added |
app/sync/initialise/styles.js | added |
app/sync/initialise/userActionListeners.js | added |
app/html/app.js | ||
---|---|---|
@@ -1,23 +1,18 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | 2 … | const { h } = require('mutant') |
3 | -const insertCss = require('insert-css') | |
4 | -const electron = require('electron') | |
5 | 3 … | |
6 | 4 … | exports.gives = nest('app.html.app') |
7 | 5 … | |
8 | 6 … | exports.needs = nest({ |
9 | - 'app.async.catchLinkClick': 'first', | |
10 | 7 … | 'app.html.tabs': 'first', |
11 | 8 … | 'app.page.errors': 'first', |
12 | - 'app.sync.catchKeyboardShortcut': 'first', | |
13 | 9 … | 'app.sync.goTo': 'first', |
14 | 10 … | 'app.sync.initialise': 'first', |
15 | 11 … | 'app.sync.window': 'reduce', |
16 | 12 … | 'history.obs.location': 'first', |
17 | 13 … | 'history.sync.push': 'first', |
18 | 14 … | 'router.sync.router': 'first', |
19 | - 'styles.css': 'reduce', | |
20 | 15 … | 'settings.sync.get': 'first', |
21 | 16 … | 'settings.sync.set': 'first' |
22 | 17 … | }) |
23 | 18 … | |
@@ -26,72 +21,18 @@ | ||
26 | 21 … | |
27 | 22 … | function app () { |
28 | 23 … | console.log('STARTING app') |
29 | 24 … | |
30 | - api.app.sync.initialise() | |
31 | - | |
32 | 25 … | window = api.app.sync.window(window) |
33 | 26 … | |
34 | - const css = values(api.styles.css()).join('\n') | |
35 | - insertCss(css) | |
27 … | + const initialTabs = ['/public', '/inbox', '/notifications'] // NB router converts these to { page: '/public' } | |
28 … | + const App = h('App', api.app.html.tabs(initialTabs)) | |
36 | 29 … | |
37 | - const initialTabs = ['/public', '/inbox', '/notifications'] | |
38 | - // NB router converts these to { page: '/public' } | |
39 | - const tabs = api.app.html.tabs(initialTabs) | |
30 … | + api.app.sync.initialise(App) | |
31 … | + // runs all the functions in app/sync/initialise | |
40 | 32 … | |
41 | - const App = h('App', tabs) | |
42 | - | |
43 | - electron.ipcRenderer.on('nextTab', () => { | |
44 | - tabs.nextTab() | |
45 | - }) | |
46 | - | |
47 | - electron.ipcRenderer.on('previousTab', () => { | |
48 | - tabs.previousTab() | |
49 | - }) | |
50 | - | |
51 | - electron.ipcRenderer.on('closeTab', () => { | |
52 | - tabs.closeCurrentTab() | |
53 | - }) | |
54 | - | |
55 | - // Catch user actions | |
56 | - api.app.sync.catchKeyboardShortcut(window, { tabs }) | |
57 | - api.app.async.catchLinkClick(App) | |
58 | - | |
59 | 33 … | api.history.obs.location()(loc => api.app.sync.goTo(loc || {})) |
60 | 34 … | |
61 | - // Catch errors | |
62 | - var { container: errorPage, addError } = api.router.sync.router('/errors') | |
63 | - window.addEventListener('error', ev => { | |
64 | - if (!tabs.has('/errors')) tabs.add(errorPage, true) | |
65 | - | |
66 | - addError(ev.error || ev) | |
67 | - }) | |
68 | - | |
69 | - /// /// TODO - extract this to keep patch-lite isolated from electron | |
70 | - const { getCurrentWebContents, getCurrentWindow } = electron.remote | |
71 | - window.addEventListener('resize', () => { | |
72 | - var wc = getCurrentWebContents() | |
73 | - wc && wc.getZoomFactor((zf) => { | |
74 | - api.settings.sync.set({ | |
75 | - electron: { | |
76 | - zoomFactor: zf, | |
77 | - windowBounds: getCurrentWindow().getBounds() | |
78 | - } | |
79 | - }) | |
80 | - }) | |
81 | - }) | |
82 | - | |
83 | - var zoomFactor = api.settings.sync.get('electron.zoomFactor') | |
84 | - if (zoomFactor) { getCurrentWebContents().setZoomFactor(zoomFactor) } | |
85 | - | |
86 | - var bounds = api.settings.sync.get('electron.windowBounds') | |
87 | - if (bounds) { getCurrentWindow().setBounds(bounds) } | |
88 | - /// /// | |
89 | - | |
90 | 35 … | return App |
91 | 36 … | } |
92 | 37 … | } |
93 | 38 … | |
94 | -function values (object) { | |
95 | - const keys = Object.keys(object) | |
96 | - return keys.map(k => object[k]) | |
97 | -} |
app/sync/initialise/electronState.js | ||
---|---|---|
@@ -1,0 +1,38 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | +const electron = require('electron') | |
3 … | + | |
4 … | +exports.gives = nest('app.sync.initialise') | |
5 … | + | |
6 … | +exports.needs = nest({ | |
7 … | + 'settings.sync.get': 'first', | |
8 … | + 'settings.sync.set': 'first', | |
9 … | +}) | |
10 … | + | |
11 … | +exports.create = function (api) { | |
12 … | + return nest('app.sync.initialise', errorCatcher) | |
13 … | + | |
14 … | + function errorCatcher () { | |
15 … | + /// /// TODO - extract this to keep patch-lite isolated from electron | |
16 … | + const { getCurrentWebContents, getCurrentWindow } = electron.remote | |
17 … | + window.addEventListener('resize', () => { | |
18 … | + var wc = getCurrentWebContents() | |
19 … | + wc && wc.getZoomFactor((zf) => { | |
20 … | + api.settings.sync.set({ | |
21 … | + electron: { | |
22 … | + zoomFactor: zf, | |
23 … | + windowBounds: getCurrentWindow().getBounds() | |
24 … | + } | |
25 … | + }) | |
26 … | + }) | |
27 … | + }) | |
28 … | + | |
29 … | + var zoomFactor = api.settings.sync.get('electron.zoomFactor') | |
30 … | + if (zoomFactor) { getCurrentWebContents().setZoomFactor(zoomFactor) } | |
31 … | + | |
32 … | + var bounds = api.settings.sync.get('electron.windowBounds') | |
33 … | + if (bounds) { getCurrentWindow().setBounds(bounds) } | |
34 … | + /// /// | |
35 … | + } | |
36 … | +} | |
37 … | + | |
38 … | + |
app/sync/initialise/errorCatcher.js | ||
---|---|---|
@@ -1,0 +1,24 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | + | |
3 … | +exports.gives = nest('app.sync.initialise') | |
4 … | + | |
5 … | +exports.needs = nest({ | |
6 … | + 'router.sync.router': 'first', | |
7 … | + 'app.html.tabs': 'first' | |
8 … | +}) | |
9 … | + | |
10 … | +exports.create = function (api) { | |
11 … | + return nest('app.sync.initialise', errorCatcher) | |
12 … | + | |
13 … | + function errorCatcher () { | |
14 … | + const tabs = api.app.html.tabs() | |
15 … | + | |
16 … | + var { container: errorPage, addError } = api.router.sync.router('/errors') | |
17 … | + window.addEventListener('error', ev => { | |
18 … | + if (!tabs.has('/errors')) tabs.add(errorPage, true) | |
19 … | + | |
20 … | + addError(ev.error || ev) | |
21 … | + }) | |
22 … | + } | |
23 … | +} | |
24 … | + |
app/sync/initialise/styles.js | ||
---|---|---|
@@ -1,0 +1,24 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | +const insertCss = require('insert-css') | |
3 … | + | |
4 … | +exports.gives = nest('app.sync.initialise') | |
5 … | + | |
6 … | +exports.needs = nest({ | |
7 … | + 'styles.css': 'reduce', | |
8 … | +}) | |
9 … | + | |
10 … | + | |
11 … | +exports.create = function (api) { | |
12 … | + return nest('app.sync.initialise', styles) | |
13 … | + | |
14 … | + function styles () { | |
15 … | + const css = values(api.styles.css()).join('\n') | |
16 … | + insertCss(css) | |
17 … | + } | |
18 … | +} | |
19 … | + | |
20 … | +function values (object) { | |
21 … | + const keys = Object.keys(object) | |
22 … | + return keys.map(k => object[k]) | |
23 … | +} | |
24 … | + |
app/sync/initialise/userActionListeners.js | |||
---|---|---|---|
@@ -1,0 +1,35 @@ | |||
1 … | +const nest = require('depnest') | ||
2 … | + | ||
3 … | +exports.gives = nest('app.sync.initialise') | ||
4 … | + | ||
5 … | +exports.needs = nest({ | ||
6 … | + 'app.async.catchLinkClick': 'first', | ||
7 … | + 'app.sync.catchKeyboardShortcut': 'first', | ||
8 … | + 'app.html.tabs': 'first', | ||
9 … | +}) | ||
10 … | + | ||
11 … | + | ||
12 … | +exports.create = function (api) { | ||
13 … | + return nest('app.sync.initialise', userActionListeners) | ||
14 … | + | ||
15 … | + function userActionListeners (App) { | ||
16 … | + const tabs = api.app.html.tabs() | ||
17 … | + | ||
18 … | + api.app.sync.catchKeyboardShortcut(window) | ||
19 … | + api.app.async.catchLinkClick(App) | ||
20 … | + | ||
21 … | + electron.ipcRenderer.on('nextTab', () => { | ||
22 … | + tabs.nextTab() | ||
23 … | + }) | ||
24 … | + | ||
25 … | + electron.ipcRenderer.on('previousTab', () => { | ||
26 … | + tabs.previousTab() | ||
27 … | + }) | ||
28 … | + | ||
29 … | + electron.ipcRenderer.on('closeTab', () => { | ||
30 … | + tabs.closeCurrentTab() | ||
31 … | + }) | ||
32 … | + | ||
33 … | + } | ||
34 … | +} | ||
35 … | + |
Built with git-ssb-web