Refactor components and enhance background task management

- Updated font sizes and weights in BasalMetabolismCard, MoodCard, HealthDataCard, and NutritionRadarCard for improved readability.
- Removed loading state from MoodCard to simplify the component.
- Adjusted styles in WeightHistoryCard for better layout and spacing.
- Integrated expo-background-fetch for improved background task handling.
- Updated Info.plist to include background fetch capability.
- Enhanced background task registration and execution logic in backgroundTaskManager.
- Added debug function to manually trigger background task execution for testing purposes.
This commit is contained in:
richarjiang
2025-09-03 16:17:29 +08:00
parent 16b4fc8816
commit 8b9689b269
17 changed files with 163 additions and 85 deletions

View File

@@ -1,4 +1,5 @@
import { BackgroundTaskType as BackgroundTask, backgroundTaskManager, TaskStatusType as TaskStatus } from '@/services/backgroundTaskManager';
import * as BackgroundFetch from 'expo-background-fetch';
import { useCallback, useEffect, useState } from 'react';
export interface UseBackgroundTasksReturn {
@@ -16,7 +17,7 @@ export interface UseBackgroundTasksReturn {
cleanupTaskStatuses: () => Promise<void>;
// 后台任务状态
backgroundTaskStatus: string | null;
backgroundTaskStatus: BackgroundFetch.BackgroundFetchStatus | null;
getBackgroundTaskStatus: () => Promise<void>;
}
@@ -24,7 +25,7 @@ export const useBackgroundTasks = (): UseBackgroundTasksReturn => {
const [isInitialized, setIsInitialized] = useState(false);
const [taskStatuses, setTaskStatuses] = useState<TaskStatus[]>([]);
const [registeredTasks, setRegisteredTasks] = useState<BackgroundTask[]>([]);
const [backgroundTaskStatus, setBackgroundTaskStatus] = useState<string | null>(null);
const [backgroundTaskStatus, setBackgroundTaskStatus] = useState<BackgroundFetch.BackgroundFetchStatus | null>(null);
// 初始化
useEffect(() => {
@@ -87,7 +88,7 @@ export const useBackgroundTasks = (): UseBackgroundTasksReturn => {
const getBackgroundTaskStatus = useCallback(async () => {
try {
const status = await backgroundTaskManager.getBackgroundTaskStatus();
setBackgroundTaskStatus(status ? status.toString() : null);
setBackgroundTaskStatus(status);
} catch (error) {
console.error('获取后台任务状态失败:', error);
}