diff --git a/src/Screens.tsx b/src/Screens.tsx index 894d9757..ba3c5302 100644 --- a/src/Screens.tsx +++ b/src/Screens.tsx @@ -58,7 +58,7 @@ const Screens: React.FC = ({ localCorrupt }) => { // Update Expo Token to server useEffect(() => { - dispatch(connectInstancesPush()) + dispatch(connectInstancesPush({ mode, t })) }, []) // Prevent screenshot alert diff --git a/src/i18n/zh-Hans/screens/meSettingsPush.ts b/src/i18n/zh-Hans/screens/meSettingsPush.ts index 7609aa95..498e5684 100644 --- a/src/i18n/zh-Hans/screens/meSettingsPush.ts +++ b/src/i18n/zh-Hans/screens/meSettingsPush.ts @@ -1,13 +1,18 @@ export default { heading: '推送通知', content: { + enable: { + direct: '启用tooot推送通知', + settings: '去系统设置启用' + }, global: { heading: '启用通知', description: '通知消息将经由tooot服务器转发' }, decode: { heading: '显示通知内容', - description: '经由tooot服务器中转的通知消息已被加密,但可以允许tooot服务器解密并转发消息。tooot消息服务器源码开源,且不留存任何日志。' + description: + '经由tooot服务器中转的通知消息已被加密,但可以允许tooot服务器解密并转发消息。tooot消息服务器源码开源,且不留存任何日志。' }, follow: { heading: '新关注者' @@ -25,5 +30,9 @@ export default { heading: '投票' }, howitworks: '了解通知消息转发如何工作' + }, + error: { + message: '推送服务器错误', + description: '请在设置中重新尝试启用推送通知' } } diff --git a/src/screens/Tabs/Me/Push.tsx b/src/screens/Tabs/Me/Push.tsx index ba002e41..4055f9d8 100644 --- a/src/screens/Tabs/Me/Push.tsx +++ b/src/screens/Tabs/Me/Push.tsx @@ -4,13 +4,39 @@ import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert import { updateInstancePushDecode } from '@utils/slices/instances/updatePushDecode' import { getInstancePush } from '@utils/slices/instancesSlice' import * as WebBrowser from 'expo-web-browser' -import React, { useMemo } from 'react' +import * as Notifications from 'expo-notifications' +import React, { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { ScrollView } from 'react-native-gesture-handler' import { useDispatch, useSelector } from 'react-redux' +import layoutAnimation from '@utils/styles/layoutAnimation' +import Button from '@components/Button' +import { StyleConstants } from '@utils/styles/constants' +import { AppState, Linking } from 'react-native' const ScreenMeSettingsPush: React.FC = () => { const { t } = useTranslation('meSettingsPush') + + const [appStateVisible, setAppStateVisible] = useState(AppState.currentState) + useEffect(() => { + AppState.addEventListener('change', state => setAppStateVisible(state)) + + return () => { + AppState.removeEventListener('change', state => setAppStateVisible(state)) + } + }, []) + const [pushEnabled, setPushEnabled] = useState() + const [pushCanAskAgain, setPushCanAskAgain] = useState() + useEffect(() => { + const checkPush = async () => { + const settings = await Notifications.getPermissionsAsync() + layoutAnimation() + setPushEnabled(settings.granted) + setPushCanAskAgain(settings.canAskAgain) + } + checkPush() + }, [appStateVisible]) + const dispatch = useDispatch() const instancePush = useSelector(getInstancePush) @@ -28,7 +54,9 @@ const ScreenMeSettingsPush: React.FC = () => { dispatch( @@ -51,13 +79,40 @@ const ScreenMeSettingsPush: React.FC = () => { return ( + {pushEnabled === false ? ( + +