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