git ssb

10+

Matt McKegg / patchwork



Tree: c13ab21e2d7f512d40d15f1de8b7509721965321

Files: c13ab21e2d7f512d40d15f1de8b7509721965321 / main-window.js

3057 bytesRaw
1var combine = require('depject')
2var entry = require('depject/entry')
3var electron = require('electron')
4var h = require('mutant/h')
5var when = require('mutant/when')
6var computed = require('mutant/computed')
7var catchLinks = require('./lib/catch-links')
8var insertCss = require('insert-css')
9var nest = require('depnest')
10var LatestUpdate = require('./lib/latest-update')
11
12require('./lib/context-menu-and-spellcheck.js')
13
14module.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
114function 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