mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-15 04:43:41 +00:00
Fix network monitoring initialization - NetworkMonitor service now properly registers and listens for connectivity changes
Co-authored-by: monkeyWie <[email protected]>
This commit is contained in:
1 parent
9955e482a4
commit
5a628bb44a
3 files changed
+16
-16
No files matched your search
@@ -26,8 +26,11 @@ class NetworkMonitor extends GetxService {
|
||||
Future<void> onInit() async {
|
||||
super.onInit();
|
||||
|
||||
logInfo('NetworkMonitor.onInit() called');
|
||||
|
||||
// Only monitor network on mobile platforms
|
||||
if (!Platform.isAndroid && !Platform.isIOS) {
|
||||
logInfo('NetworkMonitor: Not on mobile platform, skipping initialization');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,8 +38,10 @@ class NetworkMonitor extends GetxService {
|
||||
|
||||
// Check initial connectivity state
|
||||
final initialResult = await _connectivity.checkConnectivity();
|
||||
logInfo('NetworkMonitor: Initial connectivity result: $initialResult');
|
||||
_updateNetworkStatus(initialResult);
|
||||
_previousNetworkType = _getNetworkType(initialResult);
|
||||
logInfo('NetworkMonitor: Initial network type: $_previousNetworkType');
|
||||
_isInitialized = true;
|
||||
|
||||
// Listen to connectivity changes
|
||||
@@ -47,7 +52,7 @@ class NetworkMonitor extends GetxService {
|
||||
},
|
||||
);
|
||||
|
||||
logInfo('Network monitor initialized');
|
||||
logInfo('Network monitor initialized successfully');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -75,11 +80,18 @@ class NetworkMonitor extends GetxService {
|
||||
}
|
||||
|
||||
void _onConnectivityChanged(List<ConnectivityResult> result) {
|
||||
if (!_isInitialized) return;
|
||||
logInfo('NetworkMonitor: Connectivity changed event received: $result');
|
||||
|
||||
if (!_isInitialized) {
|
||||
logInfo('NetworkMonitor: Not initialized yet, ignoring connectivity change');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if network auto control is enabled
|
||||
final isNetworkAutoControlEnabled = Database.instance.getNetworkAutoControl();
|
||||
logInfo('NetworkMonitor: Network auto control enabled: $isNetworkAutoControlEnabled');
|
||||
if (!isNetworkAutoControlEnabled) {
|
||||
logInfo('NetworkMonitor: Network auto control disabled, ignoring connectivity change');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user