git ssb

10+

Matt McKegg / patchwork



Tree: 71241aeb6c78c28982fd02fd568be831d379fe0e

Files: 71241aeb6c78c28982fd02fd568be831d379fe0e / main-window.js

3136 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 '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
116function 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