Skip to content

Commit 5f4b2b5

Browse files
stephanebissonStephane Bisson
andauthored
Open links with the external browser (#374)
Co-authored-by: Stephane Bisson <sbisson@wikimedia.org>
1 parent 0460cf4 commit 5f4b2b5

File tree

8 files changed

+31
-12
lines changed

8 files changed

+31
-12
lines changed

src/components/AboutApp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { h } from 'preact'
22
import { useI18n, useSoftkey } from 'hooks'
3-
import { appVersion, appInstallId } from 'utils'
3+
import { appVersion, appInstallId, openExternal } from 'utils'
44

55
export const AboutApp = ({ close }) => {
66
const i18n = useI18n()
77

88
useSoftkey('AboutApp', {
99
right: i18n('softkey-read-more'),
10-
onKeyRight: () => window.open('https://wikimediafoundation.org/'),
10+
onKeyRight: () => openExternal('https://wikimediafoundation.org/'),
1111
left: i18n('softkey-close'),
1212
onKeyLeft: close,
1313
onKeyBackspace: close

src/components/Feedback.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { h } from 'preact'
22
import { useState, useRef, useEffect } from 'preact/hooks'
33
import { useI18n, useSoftkey, useNavigation, usePopup, useOnlineStatus } from 'hooks'
4-
import { sendFeedback, confirmDialog } from 'utils'
4+
import { sendFeedback, confirmDialog, openExternal } from 'utils'
55
import { OfflinePanel } from 'components'
66

77
export const Feedback = ({ close }) => {
@@ -50,7 +50,7 @@ export const Feedback = ({ close }) => {
5050
const { index } = getCurrent()
5151
if (index > 0) {
5252
const item = items[index - 1]
53-
window.open(item.link)
53+
openExternal(item.link)
5454
}
5555
}
5656

src/components/Gallery.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { h } from 'preact'
22
import { useRef, useLayoutEffect } from 'preact/hooks'
33
import { useI18n, useSoftkey, usePopup, useRange, useArticleMediaInfo } from 'hooks'
4+
import { openExternal } from 'utils'
45

56
const MAX_DESCRIPTION_HEIGHT = 45
67

@@ -15,7 +16,7 @@ const AboutContainer = ({ mediaInfo, dir, title, caption, close }) => {
1516
right: mediaInfo && mediaInfo.filePage ? i18n('softkey-more-info') : '',
1617
onKeyRight: () => {
1718
if (mediaInfo && mediaInfo.filePage) {
18-
window.open(mediaInfo.filePage)
19+
openExternal(mediaInfo.filePage)
1920
}
2021
}
2122
}, [mediaInfo])

src/components/Settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { route } from 'preact-router'
33
import { useRef, useEffect } from 'preact/hooks'
44
import { useNavigation, useI18n, useSoftkey, usePopup } from 'hooks'
55
import { ListView, AboutApp, AboutWikipedia, PrivacyTerms, Feedback } from 'components'
6-
import { goto } from 'utils'
6+
import { goto, openExternal } from 'utils'
77

88
export const Settings = () => {
99
const containerRef = useRef()
@@ -20,7 +20,7 @@ export const Settings = () => {
2020

2121
// open link
2222
if (item.link) {
23-
window.open(item.link)
23+
openExternal(item.link)
2424
} else if (item.path) {
2525
route(item.path)
2626
} else if (item.action) {

src/hooks/useArticleLinksNavigation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { useState, useEffect } from 'preact/hooks'
22
import { useSoftkey, usePopup, useI18n } from 'hooks'
3-
import { viewport, INTERWIKI_KEYS, normalizeTitle, getDirection } from 'utils'
43
import { ArticlePreview } from 'components'
4+
import {
5+
viewport, INTERWIKI_KEYS, normalizeTitle, getDirection,
6+
openExternal
7+
} from 'utils'
58

69
const SELECTED_ATTRIBUTE = 'data-selected'
710

@@ -65,7 +68,7 @@ export const useArticleLinksNavigation = (
6568
showArticlePreview({ title, lang, dir, source })
6669
},
6770
external: ({ href }) => {
68-
window.open(href)
71+
openExternal(href)
6972
}
7073
}
7174

src/utils/goto.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { route } from 'preact-router'
2-
import { canonicalizeTitle, getAppLanguage } from 'utils'
2+
import { canonicalizeTitle, getAppLanguage, openExternal } from 'utils'
33

44
const article = (lang, title, replace = false) => {
55
if (!Array.isArray(title)) {
@@ -17,11 +17,11 @@ const tips = () => route('/tips')
1717

1818
const termsOfUse = () => {
1919
const lang = getAppLanguage()
20-
window.open(`https://foundation.m.wikimedia.org/wiki/Terms_of_Use/${lang}`)
20+
openExternal(`https://foundation.m.wikimedia.org/wiki/Terms_of_Use/${lang}`)
2121
}
2222

2323
const privacyPolicy = () => {
24-
window.open('https://foundation.m.wikimedia.org/wiki/Privacy_policy')
24+
openExternal('https://foundation.m.wikimedia.org/wiki/Privacy_policy')
2525
}
2626

2727
const back = () => window.history.back()

src/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from './mode'
1717
export * from './mwApi'
1818
export * from './normalizeTitle'
1919
export * from './onboarding'
20+
export * from './openExternal'
2021
export * from './sendErrorLog'
2122
export * from './sendEvent'
2223
export * from './sendFeedback'

src/utils/openExternal.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const openExternal = url => {
2+
if (window.MozActivity) {
3+
// eslint-disable-next-line no-new
4+
new window.MozActivity({
5+
name: 'view',
6+
data: {
7+
type: 'url',
8+
url
9+
}
10+
})
11+
} else {
12+
window.open(url)
13+
}
14+
}

0 commit comments

Comments
 (0)