git ssb

16+

Dominic / patchbay



Tree: ab0cfd9162ed08e4f61975edf5f604162dcd8b32

Files: ab0cfd9162ed08e4f61975edf5f604162dcd8b32 / app / html / app.js

2376 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const insertCss = require('insert-css')
4const electron = require('electron')
5
6exports.gives = nest('app.html.app')
7
8exports.needs = nest({
9 'app.async.catchLinkClick': 'first',
10 'app.html.tabs': 'first',
11 'app.page.errors': 'first',
12 'app.sync.catchKeyboardShortcut': 'first',
13 'app.sync.goTo': 'first',
14 'app.sync.initialise': 'first',
15 'app.sync.window': 'reduce',
16 'history.obs.location': 'first',
17 'history.sync.push': 'first',
18 'router.sync.router': 'first',
19 'styles.css': 'reduce',
20 'settings.sync.get': 'first',
21 'settings.sync.set': 'first'
22})
23
24exports.create = function (api) {
25 return nest('app.html.app', app)
26
27 function app () {
28 console.log('STARTING app')
29
30 api.app.sync.initialise()
31
32 window = api.app.sync.window(window)
33
34 const css = values(api.styles.css()).join('\n')
35 insertCss(css)
36
37 const initialTabs = ['/public', '/inbox', '/notifications']
38 // NB router converts these to { page: '/public' }
39 const tabs = api.app.html.tabs(initialTabs)
40
41 const App = h('App', tabs)
42
43 // Catch user actions
44 api.app.sync.catchKeyboardShortcut(window, { tabs })
45 api.app.async.catchLinkClick(App)
46
47 api.history.obs.location()(loc => api.app.sync.goTo(loc || {}))
48
49 // Catch errors
50 var { container: errorPage, addError } = api.router.sync.router('/errors')
51 window.addEventListener('error', ev => {
52 if (!tabs.has('/errors')) tabs.add(errorPage, true)
53
54 addError(ev.error || ev)
55 })
56
57 /// /// TODO - extract this to keep patch-lite isolated from electron
58 const { getCurrentWebContents, getCurrentWindow } = electron.remote
59 window.addEventListener('resize', () => {
60 var wc = getCurrentWebContents()
61 wc && wc.getZoomFactor((zf) => {
62 api.settings.sync.set({
63 electron: {
64 zoomFactor: zf,
65 windowBounds: getCurrentWindow().getBounds()
66 }
67 })
68 })
69 })
70
71 var zoomFactor = api.settings.sync.get('electron.zoomFactor')
72 if (zoomFactor) { getCurrentWebContents().setZoomFactor(zoomFactor) }
73
74 var bounds = api.settings.sync.get('electron.windowBounds')
75 if (bounds) { getCurrentWindow().setBounds(bounds) }
76 /// ///
77
78 return App
79 }
80}
81
82function values (object) {
83 const keys = Object.keys(object)
84 return keys.map(k => object[k])
85}
86

Built with git-ssb-web