git ssb

16+

Dominic / patchbay



Tree: 41c069304b2bd78a228c769290dcaf99d6b470c2

Files: 41c069304b2bd78a228c769290dcaf99d6b470c2 / app / html / app.js

2727 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.externalConfirm': 'first',
11 'app.html.tabs': 'first',
12 'app.page.errors': 'first',
13 'app.sync.window': 'reduce',
14 'app.sync.addPage': 'first',
15 'app.sync.catchKeyboardShortcut': 'first',
16 'router.sync.router': 'first',
17 'router.sync.normalise': '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 keyboard shortcuts
38 api.app.sync.catchKeyboardShortcut(window, { tabs })
39
40 // Catch link clicks
41 api.app.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
42 if (isExternal) return api.app.html.externalConfirm(link)
43
44 // TODO tidy up who and where this logic happens (do when adding patch-history)
45 const location = api.router.sync.normalise(link)
46 const tabId = JSON.stringify(location)
47 if (tabs.has(tabId)) tabs.select(tabId)
48 else {
49 const changeTab = !openBackground
50 api.app.sync.addPage(location, changeTab)
51 }
52 })
53
54 // Catch errors
55 var { container: errorPage, addError } = api.router.sync.router('/errors')
56 window.addEventListener('error', ev => {
57 if (!tabs.has('/errors')) tabs.add(errorPage, true)
58
59 addError(ev.error || ev)
60 })
61
62 ////// TODO - extract this to keep patch-lite isolated from electron
63 const { getCurrentWebContents, getCurrentWindow } = electron.remote
64 window.addEventListener('resize', () => {
65 var wc = getCurrentWebContents()
66 wc && wc.getZoomFactor((zf) => {
67 api.settings.sync.set({
68 electron: {
69 zoomFactor: zf,
70 windowBounds: getCurrentWindow().getBounds()
71 }
72 })
73 })
74 })
75
76 var zoomFactor = api.settings.sync.get('electron.zoomFactor')
77 if (zoomFactor)
78 getCurrentWebContents().setZoomFactor(zoomFactor)
79
80 var bounds = api.settings.sync.get('electron.windowBounds')
81 if (bounds)
82 getCurrentWindow().setBounds(bounds)
83 //////
84
85 return App
86 }
87}
88
89function values (object) {
90 const keys = Object.keys(object)
91 return keys.map(k => object[k])
92}
93

Built with git-ssb-web