Fix unable to open URL (#2453)

This commit is contained in:
Felix Häusler 2020-12-30 10:49:33 +01:00 committed by GitHub
parent cb38f99d2d
commit 0fa6c33c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -409,19 +409,20 @@ ipcMain.on('mt::ask-for-open-project-in-sidebar', async e => {
}) })
ipcMain.on('mt::format-link-click', (e, { data, dirname }) => { ipcMain.on('mt::format-link-click', (e, { data, dirname }) => {
if (!data || !data.href || typeof data.href !== 'string') { if (!data || (!data.href && !data.text)) {
return return
} }
if (URL_REG.test(data.href)) { const href = data.href || data.text
return shell.openExternal(data.href) if (URL_REG.test(href)) {
return shell.openExternal(href)
} }
let pathname = null let pathname = null
if (path.isAbsolute(data.href) && isMarkdownFile(data.href)) { if (path.isAbsolute(href) && isMarkdownFile(href)) {
pathname = data.href pathname = href
} } else if (!path.isAbsolute(href) && isMarkdownFile(path.join(dirname, href))) {
if (!path.isAbsolute(data.href) && isMarkdownFile(path.join(dirname, data.href))) { pathname = path.join(dirname, href)
pathname = path.join(dirname, data.href)
} }
if (pathname) { if (pathname) {
const win = BrowserWindow.fromWebContents(e.sender) const win = BrowserWindow.fromWebContents(e.sender)