git ssb

16+

Dominic / patchbay



Commit a20d5059cc43f723aefd7fe6e3a79aa751ded3a9

extract startup code into initialise functions. so tidy!

mix irving committed on 2/17/2018, 6:45:25 AM
Parent: d8266c2ee656afa2eaf8d2526a54ffa339e2b8ec

Files changed

app/html/app.jschanged
app/sync/initialise/electronState.jsadded
app/sync/initialise/errorCatcher.jsadded
app/sync/initialise/styles.jsadded
app/sync/initialise/userActionListeners.jsadded
app/html/app.jsView
@@ -1,23 +1,18 @@
11 const nest = require('depnest')
22 const { h } = require('mutant')
3-const insertCss = require('insert-css')
4-const electron = require('electron')
53
64 exports.gives = nest('app.html.app')
75
86 exports.needs = nest({
9- 'app.async.catchLinkClick': 'first',
107 'app.html.tabs': 'first',
118 'app.page.errors': 'first',
12- 'app.sync.catchKeyboardShortcut': 'first',
139 'app.sync.goTo': 'first',
1410 'app.sync.initialise': 'first',
1511 'app.sync.window': 'reduce',
1612 'history.obs.location': 'first',
1713 'history.sync.push': 'first',
1814 'router.sync.router': 'first',
19- 'styles.css': 'reduce',
2015 'settings.sync.get': 'first',
2116 'settings.sync.set': 'first'
2217 })
2318
@@ -26,72 +21,18 @@
2621
2722 function app () {
2823 console.log('STARTING app')
2924
30- api.app.sync.initialise()
31-
3225 window = api.app.sync.window(window)
3326
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))
3629
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
4032
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-
5933 api.history.obs.location()(loc => api.app.sync.goTo(loc || {}))
6034
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-
9035 return App
9136 }
9237 }
9338
94-function values (object) {
95- const keys = Object.keys(object)
96- return keys.map(k => object[k])
97-}
app/sync/initialise/electronState.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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