feat: Improve offline detection logic
This commit refactors the connectivity service to be more robust and less prone to UI flicker. Key changes: - Any successful API response now briefly suppresses the offline warning. This prevents the UI from flashing an offline message between regular connectivity checks. - The threshold for showing the offline warning is increased from 2 to 3 consecutive failed health checks. - The timeout for health checks is increased to better handle slow networks. - The offline warning is now suppressed if there are active data streams to avoid interrupting the user. - A custom JSON converter is added for conversation metadata to handle potential type mismatches from local storage.
This commit is contained in:
@@ -16,6 +16,7 @@ import '../auth/api_auth_interceptor.dart';
|
||||
import '../error/api_error_interceptor.dart';
|
||||
// Tool-call details are parsed in the UI layer to render collapsible blocks
|
||||
import 'persistent_streaming_service.dart';
|
||||
import 'connectivity_service.dart';
|
||||
import '../utils/debug_logger.dart';
|
||||
import '../utils/openwebui_source_parser.dart';
|
||||
|
||||
@@ -90,7 +91,26 @@ class ApiService {
|
||||
),
|
||||
);
|
||||
|
||||
// 4. Custom debug interceptor to log exactly what we're sending
|
||||
// 4. Success pings to relax offline detection.
|
||||
// Any successful API response indicates recent connectivity; suppress
|
||||
// offline transitions briefly to avoid UI flicker.
|
||||
_dio.interceptors.add(
|
||||
InterceptorsWrapper(
|
||||
onResponse: (response, handler) {
|
||||
try {
|
||||
if ((response.statusCode ?? 0) >= 200 &&
|
||||
(response.statusCode ?? 0) < 400) {
|
||||
ConnectivityService.suppressOfflineGlobally(
|
||||
const Duration(seconds: 4),
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
handler.next(response);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// 5. Custom debug interceptor to log exactly what we're sending
|
||||
if (kDebugMode) {
|
||||
_dio.interceptors.add(
|
||||
InterceptorsWrapper(
|
||||
|
||||
Reference in New Issue
Block a user