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