Files: 1e7b8b22b00038209334ed25b4c8b3e151780691 / main-window.js
3057 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 | })) |
30 | |
31 | var id = api.keys.sync.id() |
32 | var latestUpdate = LatestUpdate() |
33 | |
34 | var views = api.app.views(api.page.html.render, [ |
35 | '/public', '/private', id, '/mentions' |
36 | ]) |
37 | |
38 | insertCss(require('./styles')) |
39 | |
40 | var container = h(`MainWindow -${process.platform}`, [ |
41 | h('div.top', [ |
42 | h('span.history', [ |
43 | h('a', { |
44 | 'ev-click': views.goBack, |
45 | classList: [ when(views.canGoBack, '-active') ] |
46 | }, '<'), |
47 | h('a', { |
48 | 'ev-click': views.goForward, |
49 | classList: [ when(views.canGoForward, '-active') ] |
50 | }, '>') |
51 | ]), |
52 | h('span.nav', [ |
53 | tab('Public', '/public'), |
54 | tab('Private', '/private') |
55 | ]), |
56 | h('span.appTitle', ['Patchwork']), |
57 | h('span', [ api.app.html.search(views.setView) ]), |
58 | h('span.nav', [ |
59 | tab('Profile', id), |
60 | tab('Mentions', '/mentions') |
61 | ]) |
62 | ]), |
63 | when(latestUpdate, |
64 | h('div.info', [ |
65 | h('a.message -update', { href: 'https://github.com/mmckegg/patchwork-next/releases' }, [ |
66 | h('strong', ['Patchwork ', latestUpdate, ' has been released.']), ' Click here for more info!' |
67 | ]) |
68 | ]) |
69 | ), |
70 | views.html |
71 | ]) |
72 | |
73 | catchLinks(container, (href, external) => { |
74 | if (external) { |
75 | electron.shell.openExternal(href) |
76 | } else if (href[0] === '&') { |
77 | electron.shell.openExternal(api.blob.sync.url(href)) |
78 | } else { |
79 | views.setView(href) |
80 | } |
81 | }) |
82 | |
83 | return container |
84 | |
85 | // scoped |
86 | |
87 | function tab (name, view) { |
88 | var instance = views.get(view) |
89 | return h('a', { |
90 | 'ev-click': function (ev) { |
91 | if (instance.pendingUpdates && instance.pendingUpdates() && instance.reload) { |
92 | instance.reload() |
93 | } |
94 | }, |
95 | href: view, |
96 | classList: [ |
97 | when(selected(view), '-selected') |
98 | ] |
99 | }, [ |
100 | name, |
101 | when(instance.pendingUpdates, [ |
102 | ' (', instance.pendingUpdates, ')' |
103 | ]) |
104 | ]) |
105 | } |
106 | |
107 | function selected (view) { |
108 | return computed([views.currentView, view], (currentView, view) => { |
109 | return currentView === view |
110 | }) |
111 | } |
112 | } |
113 | |
114 | function overrideConfig (config) { |
115 | return [{ |
116 | gives: nest('config.sync.load'), |
117 | create: function (api) { |
118 | return nest('config.sync.load', () => config) |
119 | } |
120 | }] |
121 | } |
122 |
Built with git-ssb-web