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

Upstream 6b774f2dfad7f8097b80539db30cfa27a355d299 #9383

Merged
merged 3 commits into from
Jul 12, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: User notification for blocked pop-ups and redirects

We have added some functionality that reminds the user to check their browser settings
so that redirects and e.g. opening a resource in a new tab can work properly.

https://github.com/owncloud/web/issues/9377
https://github.com/owncloud/web/pull/9383
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
Action,
FileAction,
FileActionOptions,
useIsSearchActive
useIsSearchActive,
useWindowOpen
} from 'web-pkg/src/composables/actions'

import {
Expand Down Expand Up @@ -48,6 +49,8 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
return !!unref(appProviders).find((appProvider) => appProvider.enabled)
})

const { openUrl } = useWindowOpen

const { actions: acceptShareActions } = useFileActionsAcceptShare({ store })
const { actions: copyActions } = useFileActionsCopy({ store })
const { actions: deleteActions } = useFileActionsDelete({ store })
Expand Down Expand Up @@ -190,11 +193,8 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
if (configuration.options.openAppsInTab) {
const path = router.resolve(routeOpts).href
const target = `${editor.routeName}-${filePath}`
const win = window.open(path, target)
// in case popup is blocked win will be null
if (win) {
win.focus()
}

openUrl(path, target, true)
return
}

Expand Down Expand Up @@ -327,7 +327,7 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
} as any

// TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
window.open(router.resolve(routeOpts).href, '_blank')
openUrl(router.resolve(routeOpts).href, '_blank')
}

return {
Expand Down
1 change: 1 addition & 0 deletions packages/web-pkg/src/composables/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './spaces'
export * from './types'

export * from './useActionsShowDetails'
export * from './useWindowOpen'
26 changes: 26 additions & 0 deletions packages/web-pkg/src/composables/actions/useWindowOpen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useGettext } from 'vue3-gettext'
import { useStore } from 'web-pkg/src/composables'

const openUrl = (url: string, target?: string, shouldFocus?: boolean) => {
const { $gettext } = useGettext()
const store = useStore()

const win = window.open(url, target)

if (!win) {
store.dispatch('showMessage', {
title: $gettext('Pop-up and redirect block detected'),
timeout: 20,
status: 'warning',
desc: $gettext(
'Please turn on pop-ups and redirects in your browser settings to make sure everything works right.'
)
})
} else if (shouldFocus) {
win.focus()
}
}

export const useWindowOpen = {
openUrl
}