Files: c9ae2117d8cc1e874c0094e96620ff2ab36a50bc / main-window.js
3136 bytesRaw
1 | var combine = require('depject') |
2 | var entry = require('depject/entry') |
3 | var electron = require('electron') |
4 | var h = require('mutant/h') |
5 | var when = require('mutant/when') |
6 | var computed = require('mutant/computed') |
7 | var catchLinks = require('./lib/catch-links') |
8 | var insertCss = require('insert-css') |
9 | var nest = require('depnest') |
10 | var LatestUpdate = require('./lib/latest-update') |
11 | |
12 | require('./lib/context-menu-and-spellcheck.js') |
13 | |
14 | module.exports = function (config) { |
15 | var sockets = combine( |
16 | overrideConfig(config), |
17 | require('./modules'), |
18 | require('./plugs'), |
19 | require('patchcore'), |
20 | require('./overrides') |
21 | ) |
22 | |
23 | var api = entry(sockets, nest({ |
24 | 'keys.sync.id': 'first', |
25 | 'blob.sync.url': 'first', |
26 | 'page.html.render': 'first', |
27 | 'app.html.search': 'first', |
28 | 'app.views': 'first', |
29 | 'app.html.progressNotifier': 'first' |
30 | })) |
31 | |
32 | var id = api.keys.sync.id() |
33 | var latestUpdate = LatestUpdate() |
34 | |
35 | var views = api.app.views(api.page.html.render, [ |
36 | '/public', '/private', id, '/mentions' |
37 | ]) |
38 | |
39 | insertCss(require('./styles')) |
40 | |
41 | var container = h(`MainWindow -${process.platform}`, [ |
42 | h('div.top', [ |
43 | h('span.history', [ |
44 | h('a', { |
45 | 'ev-click': views.goBack, |
46 | classList: [ when(views.canGoBack, '-active') ] |
47 | }, '<'), |
48 | h('a', { |
49 | 'ev-click': views.goForward, |
50 | classList: [ when(views.canGoForward, '-active') ] |
51 | }, '>') |
52 | ]), |
53 | h('span.nav', [ |
54 | tab('Public', '/public'), |
55 | tab('Private', '/private') |
56 | ]), |
57 | h('span.appTitle', ['Patchwork']), |
58 | h('span', [ api.app.html.search(views.setView) ]), |
59 | h('span.nav', [ |
60 | tab('Profile', id), |
61 | tab('Mentions', '/mentions') |
62 | ]) |
63 | ]), |
64 | when(latestUpdate, |
65 | h('div.info', [ |
66 | h('a.message -update', { href: 'https://github.com/mmckegg/patchwork-next/releases' }, [ |
67 | h('strong', ['Patchwork ', latestUpdate, ' has been released.']), ' Click here for more info!' |
68 | ]) |
69 | ]) |
70 | ), |
71 | api.app.html.progressNotifier(), |
72 | views.html |
73 | ]) |
74 | |
75 | catchLinks(container, (href, external) => { |
76 | if (external) { |
77 | electron.shell.openExternal(href) |
78 | } else if (href[0] === '&') { |
79 | electron.shell.openExternal(api.blob.sync.url(href)) |
80 | } else { |
81 | views.setView(href) |
82 | } |
83 | }) |
84 | |
85 | return container |
86 | |
87 | // scoped |
88 | |
89 | function tab (name, view) { |
90 | var instance = views.get(view) |
91 | return h('a', { |
92 | 'ev-click': function (ev) { |
93 | if (instance.pendingUpdates && instance.pendingUpdates() && instance.reload) { |
94 | instance.reload() |
95 | } |
96 | }, |
97 | href: view, |
98 | classList: [ |
99 | when(selected(view), '-selected') |
100 | ] |
101 | }, [ |
102 | name, |
103 | when(instance.pendingUpdates, [ |
104 | ' (', instance.pendingUpdates, ')' |
105 | ]) |
106 | ]) |
107 | } |
108 | |
109 | function selected (view) { |
110 | return computed([views.currentView, view], (currentView, view) => { |
111 | return currentView === view |
112 | }) |
113 | } |
114 | } |
115 | |
116 | function overrideConfig (config) { |
117 | return [{ |
118 | gives: nest('config.sync.load'), |
119 | create: function (api) { |
120 | return nest('config.sync.load', () => config) |
121 | } |
122 | }] |
123 | } |
124 |
Built with git-ssb-web