Files
AFFiNE/packages/app/src/components/header/utils.tsx
T
2023-01-10 14:29:18 +08:00

40 lines
1.0 KiB
TypeScript

import getIsMobile from '@/utils/get-is-mobile';
import { Trans, useTranslation } from 'react-i18next';
// Inspire by https://stackoverflow.com/a/4900484/8415727
const getChromeVersion = () => {
const raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
};
const getIsChrome = () => {
return (
/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)
);
};
const minimumChromeVersion = 102;
export const shouldShowWarning = () => {
return (
!window.CLIENT_APP &&
!getIsMobile() &&
(!getIsChrome() || getChromeVersion() < minimumChromeVersion)
);
};
export const useWarningMessage = () => {
const { t } = useTranslation();
if (!getIsChrome()) {
return (
<span>
<Trans i18nKey="recommendBrowser">
We recommend the <strong>Chrome</strong> browser for optimal
experience.
</Trans>
</span>
);
}
if (getChromeVersion() < minimumChromeVersion) {
return <span>{t('upgradeBrowser')}</span>;
}
return '';
};