From 56f5cf603255c00953dad74da9801bc01e8e63d2 Mon Sep 17 00:00:00 2001 From: Yannick Chiron Date: Fri, 11 Feb 2022 17:43:36 +0100 Subject: [PATCH 1/8] feat: use cozy-intent instead of konnectorOpenUri Old `konnectorOpenUri` mechanisme is removed in favor of cozy-intent based one Those mechanisms are used to tell parent react-native app that a connector pane needs to be opened `konnectorOpenUri` required the parent react-native app to inject a token in the store's url so the store would know if executed in a react-native context or not, and then intercept navigation URLs to detect if a connector needs to be opened. This implementation was not easy to understand New implementation uses cozy-device-helper to detect if run from CozyFlagship app and the uses cozy-intent messaging service to ask for displaying a connector --- .../components/ApplicationPage/Header.jsx | 45 +++---- .../apps/components/ApplicationPage/index.jsx | 1 - .../ApplicationRouting/InstallRoute.jsx | 10 +- .../components/ApplicationRouting/index.jsx | 2 - src/ducks/apps/components/Discover.jsx | 10 -- .../components/applicationPage/header.spec.js | 119 +++++++++++++++--- 6 files changed, 126 insertions(+), 61 deletions(-) diff --git a/src/ducks/apps/components/ApplicationPage/Header.jsx b/src/ducks/apps/components/ApplicationPage/Header.jsx index f2c6af67a..a36ab8cbc 100644 --- a/src/ducks/apps/components/ApplicationPage/Header.jsx +++ b/src/ducks/apps/components/ApplicationPage/Header.jsx @@ -9,6 +9,8 @@ import { translate } from 'cozy-ui/transpiled/react/I18n' import withBreakpoints from 'cozy-ui/transpiled/react/helpers/withBreakpoints' import Intents from 'cozy-interapp' import { withClient } from 'cozy-client' +import { useWebviewIntent } from 'cozy-intent' +import { isFlagshipApp } from 'cozy-device-helper' import cozySmileIcon from 'assets/icons/icon-cozy-smile.svg' import AsyncButton from 'ducks/components/AsyncButton' @@ -29,14 +31,28 @@ export const Header = ({ parent, isInstalling, breakpoints = {}, - client, - konnectorOpenUri + client }) => { + const webviewIntent = useWebviewIntent() const { slug, installed, type, uninstallable } = app const { isMobile } = breakpoints const isCurrentAppInstalling = isInstalling === slug - const openApp = link => { - window.location.assign(link) + const openApp = () => { + if (isFlagshipApp()) { + webviewIntent.call('openApp', app.related, app) + } else { + window.location.assign(app.related) + } + } + const openConnector = () => { + if (isFlagshipApp()) { + return webviewIntent.call('openApp', app.related, app) + } else { + const intents = new Intents({ client }) + return intents.redirect('io.cozy.accounts', { + konnector: app.slug + }) + } } const isKonnector = type === APP_TYPE.KONNECTOR const isInstallDisabled = !!isUnderMaintenance(app) || isInstalling @@ -44,10 +60,6 @@ export const Header = ({ const appOrKonnectorLabel = isKonnector ? t('app_page.webapp.open') : t('app_page.konnector.open') - const related = - konnectorOpenUri && isKonnector - ? addSlugToRedirectUri(konnectorOpenUri, slug) - : app.related return (
@@ -59,20 +71,15 @@ export const Header = ({

{description}

{isInstalledAndNothingToReport(app) && !isCurrentAppInstalling ? ( - isKonnector && !konnectorOpenUri ? ( + isKonnector ? ( { - const intents = new Intents({ client }) - return intents.redirect('io.cozy.accounts', { - konnector: app.slug - }) - }} + asyncAction={openConnector} className="c-btn" label={appOrKonnectorLabel} /> ) : (