Skip to content

Commit

Permalink
fix(app): Open external links in browser instead of app window (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Sep 20, 2018
1 parent b015f58 commit 5bf5d5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app-shell/src/ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// sets up the main window ui
import {app, BrowserWindow} from 'electron'
import {app, shell, BrowserWindow} from 'electron'
import path from 'path'
import {getConfig} from './config'
import createLogger from './log'
Expand Down Expand Up @@ -42,5 +42,12 @@ export default function createUi () {
log.info(`Loading ${url}`)
mainWindow.loadURL(url, {'extraHeaders': 'pragma: no-cache\n'})

// open new windows (<a target="_blank" ...) in browser windows
mainWindow.webContents.on('new-window', (event, url) => {
log.debug('Opening external link', {url})
event.preventDefault()
shell.openExternal(url)
})

return mainWindow
}
9 changes: 8 additions & 1 deletion app/src/components/AppSettings/ReleaseNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import styles from './styles.css'
type Props = {source: ?string}

const renderer = remark().use(reactRenderer, {
remarkReactComponents: {div: React.Fragment},
remarkReactComponents: {
div: React.Fragment,
a: ExternalLink,
},
})

const DEFAULT_RELEASE_NOTES = 'We recommend upgrading to the latest version.'
Expand All @@ -25,3 +28,7 @@ export default function ReleaseNotes (props: Props) {
</div>
)
}

function ExternalLink (props) {
return <a {...props} target="_blank" rel="noopener noreferrer" />
}
1 change: 1 addition & 0 deletions app/src/components/Resources/ResourceCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function ResourceCard (props: Props) {
Component="a"
href={props.url}
target="_blank"
rel="noopener noreferrer"
className={styles.link_button}
>
View in Browser
Expand Down

0 comments on commit 5bf5d5f

Please sign in to comment.