From 25bf3ca65bf18461d2049f0330b1727147e0f9c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 Aug 2025 07:52:44 +0000 Subject: [PATCH 1/6] Initial plan From 431fdd0d548e1f5e649ee0f39a612b7e42a0bf6b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 Aug 2025 08:04:35 +0000 Subject: [PATCH 2/6] Add network auto control feature for mobile platforms Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com> --- .../app/modules/app/bindings/app_binding.dart | 2 + .../modules/setting/views/setting_view.dart | 26 ++++- ui/flutter/lib/database/database.dart | 9 ++ ui/flutter/lib/i18n/langs/en_us.dart | 2 + ui/flutter/lib/i18n/langs/zh_cn.dart | 2 + ui/flutter/lib/util/network_monitor.dart | 107 ++++++++++++++++++ ui/flutter/pubspec.yaml | 1 + 7 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 ui/flutter/lib/util/network_monitor.dart diff --git a/ui/flutter/lib/app/modules/app/bindings/app_binding.dart b/ui/flutter/lib/app/modules/app/bindings/app_binding.dart index af092f1f5..3f109299d 100644 --- a/ui/flutter/lib/app/modules/app/bindings/app_binding.dart +++ b/ui/flutter/lib/app/modules/app/bindings/app_binding.dart @@ -1,5 +1,6 @@ import 'package:get/get.dart'; +import '../../../../util/network_monitor.dart'; import '../controllers/app_controller.dart'; class AppBinding extends Bindings { @@ -8,5 +9,6 @@ class AppBinding extends Bindings { Get.lazyPut( () => AppController(), ); + Get.put(NetworkMonitor(), permanent: true); } } diff --git a/ui/flutter/lib/app/modules/setting/views/setting_view.dart b/ui/flutter/lib/app/modules/setting/views/setting_view.dart index c1b64f2be..684d11120 100644 --- a/ui/flutter/lib/app/modules/setting/views/setting_view.dart +++ b/ui/flutter/lib/app/modules/setting/views/setting_view.dart @@ -11,6 +11,7 @@ import 'package:launch_at_startup/launch_at_startup.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../../../api/model/downloader_config.dart'; +import '../../../../database/database.dart'; import '../../../../i18n/message.dart'; import '../../../../util/input_formatter.dart'; import '../../../../util/locale_manager.dart'; @@ -543,6 +544,26 @@ class SettingView extends GetView { ); } + // Network auto control setting (mobile only) + buildNetworkAutoControl() { + if (!Platform.isAndroid && !Platform.isIOS) { + return null; + } + + return ListTile( + title: Text('networkAutoControl'.tr), + subtitle: Text('networkAutoControlTip'.tr), + trailing: Switch( + value: Database.instance.getNetworkAutoControl(), + onChanged: (bool value) { + Database.instance.saveNetworkAutoControl(value); + // Trigger rebuild to update the display value + controller.update(); + }, + ), + ); + } + // advanced config proxy items start final proxy = downloaderCfg.value.proxy; final buildProxy = _buildConfigItem( @@ -985,7 +1006,10 @@ class SettingView extends GetView { Text('network'.tr), Card( child: Column( - children: _addDivider([buildProxy()]), + children: _addDivider([ + buildNetworkAutoControl(), + buildProxy(), + ].where((e) => e != null).cast().toList()), )), const Text('API'), Card( diff --git a/ui/flutter/lib/database/database.dart b/ui/flutter/lib/database/database.dart index d939b048f..8db21cd3e 100644 --- a/ui/flutter/lib/database/database.dart +++ b/ui/flutter/lib/database/database.dart @@ -10,6 +10,7 @@ const String _windowState = 'windowState'; const String _bookmark = 'bookmark'; const String _createHistory = 'createHistory'; const String _webToken = 'webToken'; +const String _networkAutoControl = 'networkAutoControl'; class Database { static final Database _instance = Database._internal(); @@ -109,4 +110,12 @@ class Database { void clearCreateHistory() { clear(_createHistory); } + + void saveNetworkAutoControl(bool enabled) { + save(_networkAutoControl, enabled); + } + + bool getNetworkAutoControl() { + return get(_networkAutoControl, (json) => json as bool) ?? false; + } } diff --git a/ui/flutter/lib/i18n/langs/en_us.dart b/ui/flutter/lib/i18n/langs/en_us.dart index da6f55478..4f9273c31 100644 --- a/ui/flutter/lib/i18n/langs/en_us.dart +++ b/ui/flutter/lib/i18n/langs/en_us.dart @@ -125,5 +125,7 @@ const enUS = { 'login_failed': 'Login failed, please check your username and password', 'login_failed_network': 'Login failed, please check your network connection', + 'networkAutoControl': 'Network Auto Control', + 'networkAutoControlTip': 'Automatically pause downloads when switching from WiFi to mobile data, and resume when switching back to WiFi', }, }; diff --git a/ui/flutter/lib/i18n/langs/zh_cn.dart b/ui/flutter/lib/i18n/langs/zh_cn.dart index acd437b63..f92afd94f 100644 --- a/ui/flutter/lib/i18n/langs/zh_cn.dart +++ b/ui/flutter/lib/i18n/langs/zh_cn.dart @@ -122,5 +122,7 @@ const zhCN = { 'login_success': '登录成功', 'login_failed': '登录失败,请检查用户名和密码', 'login_failed_network': '登录失败,请检查网络连接', + 'networkAutoControl': '网络状态自动控制', + 'networkAutoControlTip': '当网络从WiFi切换到移动数据时自动暂停下载,切换回WiFi时自动恢复下载', } }; diff --git a/ui/flutter/lib/util/network_monitor.dart b/ui/flutter/lib/util/network_monitor.dart new file mode 100644 index 000000000..0ebebc0d0 --- /dev/null +++ b/ui/flutter/lib/util/network_monitor.dart @@ -0,0 +1,107 @@ +import 'dart:async'; +import 'dart:io'; + +import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:get/get.dart'; + +import '../api/api.dart'; +import '../database/database.dart'; +import '../util/log_util.dart'; + +class NetworkMonitor extends GetxService { + static NetworkMonitor get to => Get.find(); + + late final Connectivity _connectivity; + late StreamSubscription> _connectivitySubscription; + + final _isWiFiConnected = false.obs; + bool get isWiFiConnected => _isWiFiConnected.value; + + bool _wasWiFiConnected = false; + bool _isInitialized = false; + + @override + Future onInit() async { + super.onInit(); + + // Only monitor network on mobile platforms + if (!Platform.isAndroid && !Platform.isIOS) { + return; + } + + _connectivity = Connectivity(); + + // Check initial connectivity state + final initialResult = await _connectivity.checkConnectivity(); + _updateWiFiStatus(initialResult); + _wasWiFiConnected = _isWiFiConnected.value; + _isInitialized = true; + + // Listen to connectivity changes + _connectivitySubscription = _connectivity.onConnectivityChanged.listen( + _onConnectivityChanged, + onError: (error) { + logError('Network monitoring error: $error'); + }, + ); + + logInfo('Network monitor initialized'); + } + + @override + void onClose() { + _connectivitySubscription.cancel(); + super.onClose(); + } + + void _updateWiFiStatus(List result) { + final hasWiFi = result.contains(ConnectivityResult.wifi); + _isWiFiConnected.value = hasWiFi; + } + + void _onConnectivityChanged(List result) { + if (!_isInitialized) return; + + // Check if network auto control is enabled + final isNetworkAutoControlEnabled = Database.instance.getNetworkAutoControl(); + if (!isNetworkAutoControlEnabled) { + return; + } + + _updateWiFiStatus(result); + final currentlyWiFi = _isWiFiConnected.value; + + logInfo('Network changed: wasWiFi=$_wasWiFiConnected, currentlyWiFi=$currentlyWiFi'); + + // WiFi to Mobile Data: pause all tasks + if (_wasWiFiConnected && !currentlyWiFi) { + _pauseAllDownloads(); + logInfo('Switched from WiFi to mobile data - pausing all downloads'); + } + // Mobile Data to WiFi: resume all tasks + else if (!_wasWiFiConnected && currentlyWiFi) { + _resumeAllDownloads(); + logInfo('Switched from mobile data to WiFi - resuming all downloads'); + } + + _wasWiFiConnected = currentlyWiFi; + } + + Future _pauseAllDownloads() async { + try { + await pauseAllTasks(null); + logInfo('Successfully paused all downloads due to network change'); + } catch (e) { + logError('Failed to pause all downloads: $e'); + } + } + + Future _resumeAllDownloads() async { + try { + await continueAllTasks(null); + logInfo('Successfully resumed all downloads due to network change'); + } catch (e) { + logError('Failed to resume all downloads: $e'); + } + } +} \ No newline at end of file diff --git a/ui/flutter/pubspec.yaml b/ui/flutter/pubspec.yaml index b7ceac55b..eb3e242cc 100644 --- a/ui/flutter/pubspec.yaml +++ b/ui/flutter/pubspec.yaml @@ -66,6 +66,7 @@ dependencies: toggle_switch: ^2.3.0 permission_handler: ^11.3.1 device_info_plus: ^11.1.0 + connectivity_plus: ^6.1.0 checkable_treeview: ^1.3.1 contextmenu_plus: ^1.0.1 contentsize_tabbarview: ^0.0.2 From 14df9490cfd6be38253b02f423a36bd71d71c5ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 Aug 2025 08:08:14 +0000 Subject: [PATCH 3/6] Add translations for network auto control in multiple languages Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com> --- ui/flutter/lib/i18n/langs/es_es.dart | 2 ++ ui/flutter/lib/i18n/langs/fr_fr.dart | 2 ++ ui/flutter/lib/i18n/langs/it_it.dart | 2 ++ ui/flutter/lib/i18n/langs/ja_jp.dart | 2 ++ ui/flutter/lib/i18n/langs/ru_ru.dart | 2 ++ ui/flutter/lib/i18n/langs/vi_vn.dart | 2 ++ ui/flutter/lib/i18n/langs/zh_tw.dart | 2 ++ 7 files changed, 14 insertions(+) diff --git a/ui/flutter/lib/i18n/langs/es_es.dart b/ui/flutter/lib/i18n/langs/es_es.dart index 8fa896155..d687deb8b 100644 --- a/ui/flutter/lib/i18n/langs/es_es.dart +++ b/ui/flutter/lib/i18n/langs/es_es.dart @@ -104,5 +104,7 @@ const esES = { 'taskUrl': 'URL de la Tarea', 'downloadPath': 'Ruta de Descarga', 'skipVerifyCert': 'Omitir Verificación de Certificado', + 'networkAutoControl': 'Control Automático de Red', + 'networkAutoControlTip': 'Pausar automáticamente las descargas al cambiar de WiFi a datos móviles y reanudar al volver a WiFi', }, }; \ No newline at end of file diff --git a/ui/flutter/lib/i18n/langs/fr_fr.dart b/ui/flutter/lib/i18n/langs/fr_fr.dart index 75f630ff3..a2e027f7d 100644 --- a/ui/flutter/lib/i18n/langs/fr_fr.dart +++ b/ui/flutter/lib/i18n/langs/fr_fr.dart @@ -93,5 +93,7 @@ const frFR = { 'browserExtension': 'Extension du navigateur', 'launchAtStartup': 'Lancer au démarrage', 'skipVerifyCert': 'Bypass Verifikasi Sertifikat', + 'networkAutoControl': 'Contrôle automatique du réseau', + 'networkAutoControlTip': 'Mettre automatiquement en pause les téléchargements lors du passage du WiFi aux données mobiles et reprendre lors du retour au WiFi', }, }; diff --git a/ui/flutter/lib/i18n/langs/it_it.dart b/ui/flutter/lib/i18n/langs/it_it.dart index a6e9ffb58..4a47d5ef0 100644 --- a/ui/flutter/lib/i18n/langs/it_it.dart +++ b/ui/flutter/lib/i18n/langs/it_it.dart @@ -97,5 +97,7 @@ const itIT = { 'browserExtension': 'Estensione del browser', 'launchAtStartup': "Lancia all'avvio", 'skipVerifyCert': 'Salta la verifica del certificato', + 'networkAutoControl': 'Controllo automatico della rete', + 'networkAutoControlTip': 'Mette automaticamente in pausa i download quando si passa dal WiFi ai dati mobili e riprende quando si torna al WiFi', }, }; diff --git a/ui/flutter/lib/i18n/langs/ja_jp.dart b/ui/flutter/lib/i18n/langs/ja_jp.dart index 26d999dae..b41d0668a 100644 --- a/ui/flutter/lib/i18n/langs/ja_jp.dart +++ b/ui/flutter/lib/i18n/langs/ja_jp.dart @@ -63,5 +63,7 @@ const jaJP = { 'thanksDesc': 'Gopeedコミュニティの建設に協力してくださったすべての貢献者の方々に感謝します!', 'browserExtension': 'ブラウザ拡張機能', 'skipVerifyCert': '証明書の検証をスキップ', + 'networkAutoControl': 'ネットワーク自動制御', + 'networkAutoControlTip': 'WiFiからモバイルデータに切り替わった時に自動的にダウンロードを一時停止し、WiFiに戻った時に自動的に再開します', } }; diff --git a/ui/flutter/lib/i18n/langs/ru_ru.dart b/ui/flutter/lib/i18n/langs/ru_ru.dart index 6bb59ce57..dfc13433a 100644 --- a/ui/flutter/lib/i18n/langs/ru_ru.dart +++ b/ui/flutter/lib/i18n/langs/ru_ru.dart @@ -119,5 +119,7 @@ const ruRU = { 'fileSelectedSize': 'Размер: ', 'httpHeaderName': 'Название заголовка HTTP', 'httpHeaderValue': 'Значение заголовка HTTP', + 'networkAutoControl': 'Автоматическое управление сетью', + 'networkAutoControlTip': 'Автоматически приостанавливать загрузки при переключении с WiFi на мобильные данные и возобновлять при возврате к WiFi', } }; diff --git a/ui/flutter/lib/i18n/langs/vi_vn.dart b/ui/flutter/lib/i18n/langs/vi_vn.dart index 309fdf69b..96054c654 100644 --- a/ui/flutter/lib/i18n/langs/vi_vn.dart +++ b/ui/flutter/lib/i18n/langs/vi_vn.dart @@ -90,5 +90,7 @@ const viVN = { 'Cảm ơn tất cả những người đóng góp đã giúp xây dựng và phát triển cộng đồng Gopeed!', 'browserExtension': 'Tiện ích mở rộng trình duyệt', 'skipVerifyCert': 'Bỏ qua xác thực chứng chỉ', + 'networkAutoControl': 'Điều khiển mạng tự động', + 'networkAutoControlTip': 'Tự động tạm dừng tải xuống khi chuyển từ WiFi sang dữ liệu di động và tiếp tục khi quay lại WiFi', }, }; diff --git a/ui/flutter/lib/i18n/langs/zh_tw.dart b/ui/flutter/lib/i18n/langs/zh_tw.dart index 35701c18e..d9497e841 100644 --- a/ui/flutter/lib/i18n/langs/zh_tw.dart +++ b/ui/flutter/lib/i18n/langs/zh_tw.dart @@ -116,5 +116,7 @@ const zhTW = { 'fileSelectedSize': '大小:', 'httpHeaderName': '標頭名稱', 'httpHeaderValue': '標頭值', + 'networkAutoControl': '網路狀態自動控制', + 'networkAutoControlTip': '當網路從WiFi切換到流動數據時自動暫停下載,切換回WiFi時自動恢復下載', } }; From 27dc7aea5274e538903c0b17710ccf7ac92fe161 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 Aug 2025 08:11:00 +0000 Subject: [PATCH 4/6] Make network auto control setting reactive with proper GetX observable Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com> --- .../setting/controllers/setting_controller.dart | 10 ++++++++++ .../lib/app/modules/setting/views/setting_view.dart | 10 ++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ui/flutter/lib/app/modules/setting/controllers/setting_controller.dart b/ui/flutter/lib/app/modules/setting/controllers/setting_controller.dart index f9cedd026..fc724c66e 100644 --- a/ui/flutter/lib/app/modules/setting/controllers/setting_controller.dart +++ b/ui/flutter/lib/app/modules/setting/controllers/setting_controller.dart @@ -1,15 +1,19 @@ import 'package:get/get.dart'; +import '../../../../database/database.dart'; import '../../../../util/updater.dart'; class SettingController extends GetxController { final tapStatues = {}.obs; final latestVersion = Rxn(); + final networkAutoControl = false.obs; @override void onInit() { super.onInit(); fetchLatestVersion(); + // Initialize network auto control setting + networkAutoControl.value = Database.instance.getNetworkAutoControl(); } // set all tap status to false @@ -27,4 +31,10 @@ class SettingController extends GetxController { void fetchLatestVersion() async { latestVersion.value = await checkUpdate(); } + + // update network auto control setting + void updateNetworkAutoControl(bool value) { + networkAutoControl.value = value; + Database.instance.saveNetworkAutoControl(value); + } } diff --git a/ui/flutter/lib/app/modules/setting/views/setting_view.dart b/ui/flutter/lib/app/modules/setting/views/setting_view.dart index 684d11120..62d4a436d 100644 --- a/ui/flutter/lib/app/modules/setting/views/setting_view.dart +++ b/ui/flutter/lib/app/modules/setting/views/setting_view.dart @@ -550,18 +550,16 @@ class SettingView extends GetView { return null; } - return ListTile( + return Obx(() => ListTile( title: Text('networkAutoControl'.tr), subtitle: Text('networkAutoControlTip'.tr), trailing: Switch( - value: Database.instance.getNetworkAutoControl(), + value: controller.networkAutoControl.value, onChanged: (bool value) { - Database.instance.saveNetworkAutoControl(value); - // Trigger rebuild to update the display value - controller.update(); + controller.updateNetworkAutoControl(value); }, ), - ); + )); } // advanced config proxy items start From 9955e482a41e92e662856b24759533e51dc2951b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 Aug 2025 09:08:38 +0000 Subject: [PATCH 5/6] =?UTF-8?q?Fix=20network=20detection=20logic=20to=20pr?= =?UTF-8?q?operly=20handle=20WiFi=20=E2=86=94=20Mobile=20transitions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com> --- ui/flutter/lib/util/network_monitor.dart | 41 ++++++++++++++++-------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/ui/flutter/lib/util/network_monitor.dart b/ui/flutter/lib/util/network_monitor.dart index 0ebebc0d0..fe4768682 100644 --- a/ui/flutter/lib/util/network_monitor.dart +++ b/ui/flutter/lib/util/network_monitor.dart @@ -8,6 +8,8 @@ import '../api/api.dart'; import '../database/database.dart'; import '../util/log_util.dart'; +enum NetworkType { wifi, mobile, other, none } + class NetworkMonitor extends GetxService { static NetworkMonitor get to => Get.find(); @@ -17,7 +19,7 @@ class NetworkMonitor extends GetxService { final _isWiFiConnected = false.obs; bool get isWiFiConnected => _isWiFiConnected.value; - bool _wasWiFiConnected = false; + NetworkType _previousNetworkType = NetworkType.none; bool _isInitialized = false; @override @@ -33,8 +35,8 @@ class NetworkMonitor extends GetxService { // Check initial connectivity state final initialResult = await _connectivity.checkConnectivity(); - _updateWiFiStatus(initialResult); - _wasWiFiConnected = _isWiFiConnected.value; + _updateNetworkStatus(initialResult); + _previousNetworkType = _getNetworkType(initialResult); _isInitialized = true; // Listen to connectivity changes @@ -54,7 +56,20 @@ class NetworkMonitor extends GetxService { super.onClose(); } - void _updateWiFiStatus(List result) { + NetworkType _getNetworkType(List result) { + if (result.contains(ConnectivityResult.wifi)) { + return NetworkType.wifi; + } else if (result.contains(ConnectivityResult.mobile)) { + return NetworkType.mobile; + } else if (result.contains(ConnectivityResult.none)) { + return NetworkType.none; + } else { + // Ethernet, Bluetooth, VPN, or other connection types + return NetworkType.other; + } + } + + void _updateNetworkStatus(List result) { final hasWiFi = result.contains(ConnectivityResult.wifi); _isWiFiConnected.value = hasWiFi; } @@ -68,23 +83,23 @@ class NetworkMonitor extends GetxService { return; } - _updateWiFiStatus(result); - final currentlyWiFi = _isWiFiConnected.value; + _updateNetworkStatus(result); + final currentNetworkType = _getNetworkType(result); - logInfo('Network changed: wasWiFi=$_wasWiFiConnected, currentlyWiFi=$currentlyWiFi'); + logInfo('Network changed: previous=$_previousNetworkType, current=$currentNetworkType'); - // WiFi to Mobile Data: pause all tasks - if (_wasWiFiConnected && !currentlyWiFi) { + // Only handle WiFi ↔ Mobile transitions, ignore other connection types + if (_previousNetworkType == NetworkType.wifi && currentNetworkType == NetworkType.mobile) { _pauseAllDownloads(); logInfo('Switched from WiFi to mobile data - pausing all downloads'); - } - // Mobile Data to WiFi: resume all tasks - else if (!_wasWiFiConnected && currentlyWiFi) { + } else if (_previousNetworkType == NetworkType.mobile && currentNetworkType == NetworkType.wifi) { _resumeAllDownloads(); logInfo('Switched from mobile data to WiFi - resuming all downloads'); + } else { + logInfo('Network change ignored: not a WiFi ↔ Mobile transition'); } - _wasWiFiConnected = currentlyWiFi; + _previousNetworkType = currentNetworkType; } Future _pauseAllDownloads() async { From 5a628bb44a659884cdad88f636cd6bdd2a57380c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 Aug 2025 09:37:50 +0000 Subject: [PATCH 6/6] Fix network monitoring initialization - NetworkMonitor service now properly registers and listens for connectivity changes Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com> --- .../app/modules/app/bindings/app_binding.dart | 14 -------------- .../app/modules/root/bindings/root_binding.dart | 2 ++ ui/flutter/lib/util/network_monitor.dart | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 ui/flutter/lib/app/modules/app/bindings/app_binding.dart diff --git a/ui/flutter/lib/app/modules/app/bindings/app_binding.dart b/ui/flutter/lib/app/modules/app/bindings/app_binding.dart deleted file mode 100644 index 3f109299d..000000000 --- a/ui/flutter/lib/app/modules/app/bindings/app_binding.dart +++ /dev/null @@ -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(), - ); - Get.put(NetworkMonitor(), permanent: true); - } -} diff --git a/ui/flutter/lib/app/modules/root/bindings/root_binding.dart b/ui/flutter/lib/app/modules/root/bindings/root_binding.dart index 2a106a1d4..9ae0a49f0 100644 --- a/ui/flutter/lib/app/modules/root/bindings/root_binding.dart +++ b/ui/flutter/lib/app/modules/root/bindings/root_binding.dart @@ -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(), fenix: true); + Get.put(NetworkMonitor(), permanent: true); } } diff --git a/ui/flutter/lib/util/network_monitor.dart b/ui/flutter/lib/util/network_monitor.dart index fe4768682..10417f219 100644 --- a/ui/flutter/lib/util/network_monitor.dart +++ b/ui/flutter/lib/util/network_monitor.dart @@ -26,8 +26,11 @@ class NetworkMonitor extends GetxService { Future 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 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; }