git ssb

16+

Dominic / patchbay



Tree: 31a6b451195783f711ecd29057d9dc3ea60f92aa

Files: 31a6b451195783f711ecd29057d9dc3ea60f92aa / app / html / app.js

2518 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 window.addEventListener('resize', function(e){
63 var wc = electron.remote.getCurrentWebContents()
64 wc && wc.getZoomFactor((zf) => {
65 api.settings.sync.set({
66 zoomFactor: zf,
67 bounds: electron.remote.getCurrentWindow().getBounds()
68 })
69 })
70 })
71
72 var zoomFactor = api.settings.sync.get('zoom')
73 if (zoomFactor)
74 electron.remote.getCurrentWebContents().setZoomFactor(zoomFactor)
75 var bounds = api.settings.sync.get('bounds')
76 if (bounds)
77 electron.remote.getCurrentWindow().setBounds(bounds)
78
79 return App
80 }
81}
82
83function values (object) {
84 const keys = Object.keys(object)
85 return keys.map(k => object[k])
86}
87

Built with git-ssb-web