git ssb

16+

Dominic / patchbay



Tree: 5bb810bd56a8aa605ec54bb509fe43d9b30e31b7

Files: 5bb810bd56a8aa605ec54bb509fe43d9b30e31b7 / app / html / app.js

2380 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)
73 getCurrentWebContents().setZoomFactor(zoomFactor)
74
75 var bounds = api.settings.sync.get('electron.windowBounds')
76 if (bounds)
77 getCurrentWindow().setBounds(bounds)
78 //////
79
80 return App
81 }
82}
83
84function values (object) {
85 const keys = Object.keys(object)
86 return keys.map(k => object[k])
87}
88

Built with git-ssb-web