git ssb

16+

Dominic / patchbay



Tree: 958235c2141b96dc42b5dff7893d5906dc1bdfd1

Files: 958235c2141b96dc42b5dff7893d5906dc1bdfd1 / app / html / app.js

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

Built with git-ssb-web