main-window.jsView |
---|
15 | 15 | |
16 | 16 | module.exports = function (config) { |
17 | 17 | var sockets = combine( |
18 | 18 | overrideConfig(config), |
19 | | - addCommand('app.navigate', setView), |
| 19 | + addCommand('app.navigate', navigate), |
20 | 20 | require('./modules'), |
21 | 21 | require('./plugs'), |
22 | 22 | require('patch-settings'), |
23 | 23 | require('patchcore'), |
139 | 139 | |
140 | 140 | var previewElement = api.app.linkPreview(container, 500) |
141 | 141 | |
142 | 142 | catchLinks(container, (href, external, anchor) => { |
| 143 | + if (!href) return |
143 | 144 | if (external) { |
144 | 145 | electron.shell.openExternal(href) |
145 | | - } else if (href && href.startsWith('&')) { |
146 | | - electron.shell.openExternal(api.blob.sync.url(href)) |
147 | | - } else if (ref.isMsg(href)) { |
148 | | - getExternalHandler(href, (err, handler) => { |
149 | | - if (!err && handler) { |
150 | | - handler(href) |
151 | | - } else { |
152 | | - api.app.navigate(href, anchor) |
153 | | - } |
154 | | - }) |
155 | 146 | } else { |
156 | | - api.app.navigate(href, anchor) |
| 147 | + api.app.navigate(href) |
157 | 148 | } |
158 | 149 | }) |
159 | 150 | |
160 | 151 | return [container, previewElement] |
169 | 160 | label: i18n('Channels'), |
170 | 161 | submenu: [ |
171 | 162 | { label: i18n('Browse All'), |
172 | 163 | click () { |
173 | | - setView('/channels') |
| 164 | + navigate('/channels') |
174 | 165 | } |
175 | 166 | }, |
176 | 167 | {type: 'separator'} |
177 | 168 | ].concat(channels.map(channel => { |
178 | 169 | return { |
179 | 170 | label: `#${channel}`, |
180 | 171 | click () { |
181 | | - setView(`#${channel}`) |
| 172 | + navigate(`#${channel}`) |
182 | 173 | } |
183 | 174 | } |
184 | 175 | })) |
185 | 176 | } |
186 | 177 | } else { |
187 | 178 | return { |
188 | 179 | label: i18n('Browse Channels'), |
189 | 180 | click () { |
190 | | - setView('/channels') |
| 181 | + navigate('/channels') |
191 | 182 | } |
192 | 183 | } |
193 | 184 | } |
194 | 185 | } |
206 | 197 | } else { |
207 | 198 | return { |
208 | 199 | label: item[0], |
209 | 200 | click () { |
210 | | - setView(item[1]) |
| 201 | + navigate(item[1]) |
211 | 202 | } |
212 | 203 | } |
213 | 204 | } |
214 | 205 | })) |
222 | 213 | }, title) |
223 | 214 | return element |
224 | 215 | } |
225 | 216 | |
226 | | - function setView (href, anchor) { |
227 | | - previewElement.cancel() |
228 | | - views.setView(href, anchor) |
| 217 | + function navigate (href, anchor) { |
| 218 | + if (typeof href !== 'string') return false |
| 219 | + getExternalHandler(href, (err, handler) => { |
| 220 | + if (!err && handler) { |
| 221 | + handler(href) |
| 222 | + } else { |
| 223 | + |
| 224 | + previewElement.cancel() |
| 225 | + views.setView(href, anchor) |
| 226 | + } |
| 227 | + }) |
229 | 228 | } |
230 | 229 | |
231 | | - function getExternalHandler (key, cb) { |
232 | | - api.sbot.async.get(key, function (err, value) { |
233 | | - if (err) return cb(err) |
234 | | - cb(null, api.app.sync.externalHandler({key, value})) |
235 | | - }) |
| 230 | + function getExternalHandler (href, cb) { |
| 231 | + var link = ref.parseLink(href) |
| 232 | + if (link && ref.isMsg(link.link)) { |
| 233 | + api.sbot.async.get(link.link, function (err, value) { |
| 234 | + if (err) return cb(err) |
| 235 | + cb(null, api.app.sync.externalHandler({key: link.link, value, query: link.query})) |
| 236 | + }) |
| 237 | + } else { |
| 238 | + cb() |
| 239 | + } |
236 | 240 | } |
237 | 241 | |
238 | 242 | function tab (name, view) { |
239 | 243 | var instance = views.get(view) |