feat: 优化代码
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { listChallenges } from '@/services/challengesApi';
|
||||
import { store } from '@/store';
|
||||
import { getWaterIntakeFromHealthKit } from '@/utils/health';
|
||||
import AsyncStorage from '@/utils/kvStore';
|
||||
import { log } from '@/utils/logger';
|
||||
import { listChallenges } from '@/services/challengesApi';
|
||||
import { ChallengeNotificationHelpers, StandReminderHelpers, WaterNotificationHelpers } from '@/utils/notificationHelpers';
|
||||
import { getWaterIntakeFromHealthKit } from '@/utils/health';
|
||||
import { ChallengeNotificationHelpers, WaterNotificationHelpers } from '@/utils/notificationHelpers';
|
||||
import { getWaterGoalFromStorage } from '@/utils/userPreferences';
|
||||
import dayjs from 'dayjs';
|
||||
import * as BackgroundTask from 'expo-background-task';
|
||||
import * as TaskManager from 'expo-task-manager';
|
||||
import { TaskManagerTaskBody } from 'expo-task-manager';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export const BACKGROUND_TASK_IDENTIFIER = 'com.anonymous.digitalpilates.task';
|
||||
|
||||
@@ -107,34 +107,6 @@ async function executeWaterReminderTask(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// 执行站立提醒后台任务
|
||||
async function executeStandReminderTask(): Promise<void> {
|
||||
try {
|
||||
console.log('执行站立提醒后台任务...');
|
||||
|
||||
// 获取当前状态
|
||||
const state = store.getState();
|
||||
const userProfile = state.user.profile;
|
||||
|
||||
// 获取用户名
|
||||
const userName = userProfile?.name || '朋友';
|
||||
|
||||
// 调用站立提醒检查函数
|
||||
const notificationSent = await StandReminderHelpers.checkStandStatusAndNotify(userName);
|
||||
|
||||
if (notificationSent) {
|
||||
console.log('后台站立提醒通知已发送');
|
||||
// 记录后台任务执行时间
|
||||
await AsyncStorage.setItem('@last_background_stand_check', Date.now().toString());
|
||||
} else {
|
||||
console.log('无需发送后台站立提醒通知');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('执行站立提醒后台任务失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function executeChallengeReminderTask(): Promise<void> {
|
||||
try {
|
||||
console.log('执行挑战鼓励提醒后台任务...');
|
||||
|
||||
Reference in New Issue
Block a user