mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 08:30:29 +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
@@ -1,14 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../util/network_monitor.dart';
|
||||
import '../controllers/app_controller.dart';
|
||||
|
||||
class AppBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<AppController>(
|
||||
() => AppController(),
|
||||
);
|
||||
Get.put<NetworkMonitor>(NetworkMonitor(), permanent: true);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../util/network_monitor.dart';
|
||||
import '../controllers/root_controller.dart';
|
||||
|
||||
class RootBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<RootController>(() => RootController(), fenix: true);
|
||||
Get.put<NetworkMonitor>(NetworkMonitor(), permanent: true);
|
||||
}
|
||||
}
|
||||
@@ -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