Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): Open external links in user's browser instead of app window #2327

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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