Reduce noisy runtime logging in frontend flows.
This keeps chat, notification, and post interactions cleaner in production while preserving error-level visibility.
This commit is contained in:
@@ -46,12 +46,9 @@ let appStateSubscription: any = null;
|
||||
|
||||
// 定义后台任务
|
||||
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
|
||||
console.log('[BackgroundService] 后台任务执行中...');
|
||||
|
||||
try {
|
||||
// 检查 WebSocket 连接状态
|
||||
if (!websocketService.isConnected()) {
|
||||
console.log('[BackgroundService] WebSocket 断开,尝试重连');
|
||||
await websocketService.connect();
|
||||
}
|
||||
|
||||
@@ -65,11 +62,8 @@ TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
|
||||
|
||||
// WebSocket 保活任务
|
||||
TaskManager.defineTask(WEBSOCKET_KEEPALIVE_TASK, async () => {
|
||||
console.log('[BackgroundService] WebSocket 保活任务执行...');
|
||||
|
||||
try {
|
||||
if (!websocketService.isConnected()) {
|
||||
console.log('[BackgroundService] WebSocket 断开,尝试重连');
|
||||
await websocketService.connect();
|
||||
}
|
||||
return BackgroundFetch.BackgroundFetchResult.NewData;
|
||||
@@ -178,7 +172,6 @@ async function registerBackgroundTasks(): Promise<void> {
|
||||
stopOnTerminate: false, // App 终止后继续运行
|
||||
startOnBoot: true, // 设备启动后自动运行
|
||||
});
|
||||
console.log('[BackgroundService] 后台任务注册成功');
|
||||
}
|
||||
|
||||
// 注册 WebSocket 保活任务
|
||||
@@ -189,7 +182,6 @@ async function registerBackgroundTasks(): Promise<void> {
|
||||
stopOnTerminate: false,
|
||||
startOnBoot: true,
|
||||
});
|
||||
console.log('[BackgroundService] WebSocket 保活任务注册成功');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[BackgroundService] 注册后台任务失败:', error);
|
||||
@@ -203,7 +195,6 @@ async function unregisterBackgroundTasks(): Promise<void> {
|
||||
try {
|
||||
await BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK);
|
||||
await BackgroundFetch.unregisterTaskAsync(WEBSOCKET_KEEPALIVE_TASK);
|
||||
console.log('[BackgroundService] 后台任务已取消');
|
||||
} catch (error) {
|
||||
console.error('[BackgroundService] 取消后台任务失败:', error);
|
||||
}
|
||||
@@ -218,17 +209,12 @@ function setupAppStateListener(): void {
|
||||
}
|
||||
|
||||
appStateSubscription = AppState.addEventListener('change', (nextAppState: AppStateStatus) => {
|
||||
console.log('[BackgroundService] App 状态变化:', nextAppState);
|
||||
|
||||
void nextAppState;
|
||||
if (nextAppState === 'active') {
|
||||
// App 回到前台,确保连接
|
||||
console.log('[BackgroundService] App 回到前台');
|
||||
if (!websocketService.isConnected()) {
|
||||
websocketService.connect();
|
||||
}
|
||||
} else if (nextAppState === 'background') {
|
||||
// App 进入后台,启动保活
|
||||
console.log('[BackgroundService] App 进入后台,启动保活机制');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -238,13 +224,10 @@ function setupAppStateListener(): void {
|
||||
*/
|
||||
export async function initBackgroundService(): Promise<boolean> {
|
||||
if (isInitialized) {
|
||||
console.log('[BackgroundService] 服务已初始化');
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[BackgroundService] 初始化后台保活服务...');
|
||||
|
||||
// 检查后台任务状态
|
||||
const status = await BackgroundFetch.getStatusAsync();
|
||||
if (status !== BackgroundFetch.BackgroundFetchStatus.Available) {
|
||||
@@ -259,7 +242,6 @@ export async function initBackgroundService(): Promise<boolean> {
|
||||
setupAppStateListener();
|
||||
|
||||
isInitialized = true;
|
||||
console.log('[BackgroundService] 后台保活服务初始化完成');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[BackgroundService] 初始化失败:', error);
|
||||
@@ -280,7 +262,6 @@ export async function stopBackgroundService(): Promise<void> {
|
||||
}
|
||||
|
||||
isInitialized = false;
|
||||
console.log('[BackgroundService] 后台保活服务已停止');
|
||||
} catch (error) {
|
||||
console.error('[BackgroundService] 停止服务失败:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user