git ssb

10+

Matt McKegg / patchwork



Tree: ca2f1cdb9f35a2cf90f43e41e0a9670809627406

Files: ca2f1cdb9f35a2cf90f43e41e0a9670809627406 / main-window.js

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

Built with git-ssb-web