mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 06:13:42 +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 'package:get/get.dart';
|
||||||
|
|
||||||
|
import '../../../../util/network_monitor.dart';
|
||||||
import '../controllers/root_controller.dart';
|
import '../controllers/root_controller.dart';
|
||||||
|
|
||||||
class RootBinding extends Bindings {
|
class RootBinding extends Bindings {
|
||||||
@override
|
@override
|
||||||
void dependencies() {
|
void dependencies() {
|
||||||
Get.lazyPut<RootController>(() => RootController(), fenix: true);
|
Get.lazyPut<RootController>(() => RootController(), fenix: true);
|
||||||
|
Get.put<NetworkMonitor>(NetworkMonitor(), permanent: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,11 @@ class NetworkMonitor extends GetxService {
|
|||||||
Future<void> onInit() async {
|
Future<void> onInit() async {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
|
||||||
|
logInfo('NetworkMonitor.onInit() called');
|
||||||
|
|
||||||
// Only monitor network on mobile platforms
|
// Only monitor network on mobile platforms
|
||||||
if (!Platform.isAndroid && !Platform.isIOS) {
|
if (!Platform.isAndroid && !Platform.isIOS) {
|
||||||
|
logInfo('NetworkMonitor: Not on mobile platform, skipping initialization');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +38,10 @@ class NetworkMonitor extends GetxService {
|
|||||||
|
|
||||||
// Check initial connectivity state
|
// Check initial connectivity state
|
||||||
final initialResult = await _connectivity.checkConnectivity();
|
final initialResult = await _connectivity.checkConnectivity();
|
||||||
|
logInfo('NetworkMonitor: Initial connectivity result: $initialResult');
|
||||||
_updateNetworkStatus(initialResult);
|
_updateNetworkStatus(initialResult);
|
||||||
_previousNetworkType = _getNetworkType(initialResult);
|
_previousNetworkType = _getNetworkType(initialResult);
|
||||||
|
logInfo('NetworkMonitor: Initial network type: $_previousNetworkType');
|
||||||
_isInitialized = true;
|
_isInitialized = true;
|
||||||
|
|
||||||
// Listen to connectivity changes
|
// Listen to connectivity changes
|
||||||
@@ -47,7 +52,7 @@ class NetworkMonitor extends GetxService {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
logInfo('Network monitor initialized');
|
logInfo('Network monitor initialized successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -75,11 +80,18 @@ class NetworkMonitor extends GetxService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onConnectivityChanged(List<ConnectivityResult> result) {
|
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
|
// Check if network auto control is enabled
|
||||||
final isNetworkAutoControlEnabled = Database.instance.getNetworkAutoControl();
|
final isNetworkAutoControlEnabled = Database.instance.getNetworkAutoControl();
|
||||||
|
logInfo('NetworkMonitor: Network auto control enabled: $isNetworkAutoControlEnabled');
|
||||||
if (!isNetworkAutoControlEnabled) {
|
if (!isNetworkAutoControlEnabled) {
|
||||||
|
logInfo('NetworkMonitor: Network auto control disabled, ignoring connectivity change');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user