import { Trans, useTranslation } from 'react-i18next'; import semver from 'semver'; import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import { Divider, List, ListItemButton, Switch } from '@mui/material'; import { TimePicker } from '@mui/x-date-pickers/TimePicker'; import { ListItem, ListItemText } from '@/components/ListItem'; import { usePromiseValue } from '@/helpers/useServiceValue'; import { usePreferenceObservable } from '@services/preferences/hooks'; import { WindowNames } from '@services/windows/WindowProperties'; import { Link, ListItemVertical, Paper, SectionTitle, TimePickerContainer } from '../PreferenceComponents'; import type { ISectionProps } from '../useSections'; export function Notifications(props: Required): React.JSX.Element { const { t } = useTranslation(); const preference = usePreferenceObservable(); const platformAndVersion = usePromiseValue( async () => await Promise.all([window.service.context.get('platform'), window.service.context.get('oSVersion')]).catch((error: unknown) => { void window.service.native.log('error', 'Preferences: Notifications load failed', { function: 'Notifications.useEffect', error }); return [undefined, undefined]; }), [undefined, undefined], ); const platform = platformAndVersion?.[0]; const oSVersion = platformAndVersion?.[1]; return ( <> {t('Preference.Notifications')} {preference === undefined || platform === undefined ? {t('Loading')} : ( <> { await window.service.window.open(WindowNames.notifications); }} > { await window.service.preference.set('pauseNotificationsByScheduleFrom', (d ?? '').toString()); }} onClose={async () => { await window.service.window.updateWindowMeta(WindowNames.preferences, { preventClosingWindow: false }); }} onOpen={async () => { await window.service.window.updateWindowMeta(WindowNames.preferences, { preventClosingWindow: true }); }} disabled={!preference.pauseNotificationsBySchedule} /> { await window.service.preference.set('pauseNotificationsByScheduleTo', (d ?? '').toString()); }} onClose={async () => { await window.service.window.updateWindowMeta(WindowNames.preferences, { preventClosingWindow: false }); }} onOpen={async () => { await window.service.window.updateWindowMeta(WindowNames.preferences, { preventClosingWindow: true }); }} disabled={!preference.pauseNotificationsBySchedule} /> ({window.Intl.DateTimeFormat().resolvedOptions().timeZone}) { await window.service.preference.set('pauseNotificationsBySchedule', event.target.checked); }} /> { await window.service.preference.set('pauseNotificationsMuteAudio', event.target.checked); }} /> } > { await window.service.preference.set('unreadCountBadge', event.target.checked); props.requestRestartCountDown(); }} /> } > { void window.service.notification.show({ title: t('Preference.TestNotification'), body: t('Preference.ItIsWorking'), }); }} > { // only show this message on macOS Catalina 10.15 & above if (platform === 'darwin' && oSVersion !== undefined && semver.gte(oSVersion, '10.15.0')) { return ( If notifications dont show up, make sure you enable notifications in macOS Preferences → Notifications → TidGi. ); } })()} /> TidGi supports notifications out of the box. But for some cases, to receive notifications, you will need to manually configure additional web app settings. { await window.service.native.openURI('https://github.com/atomery/webcatalog/wiki/How-to-Enable-Notifications-in-Web-Apps'); }} onKeyDown={(event: React.KeyboardEvent) => { if (event.key !== 'Enter') return; void window.service.native.openURI('https://github.com/atomery/webcatalog/wiki/How-to-Enable-Notifications-in-Web-Apps'); }} > Learn more . } /> )} ); }