From 49d7268300dad123f7ea6bd2b8239a9edb6801b4 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Fri, 27 Oct 2023 19:12:46 +0330 Subject: [PATCH] Remove reconnect on auto profile update --- CHANGELOG.md | 3 +++ .../connectivity/connectivity_controller.dart | 2 +- .../profiles/notifier/profiles_notifier.dart | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7be271f..66c55566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,3 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Localization mistakes in Russian from [solokot](https://github.com/solokot) - Localization mistakes in Russian from [Elshad Guseynov](https://github.com/lifeindarkside) - Logs filtering + +### Removed +- Reconnect on auto profile update diff --git a/lib/features/common/connectivity/connectivity_controller.dart b/lib/features/common/connectivity/connectivity_controller.dart index d0a17ce9..84564fac 100644 --- a/lib/features/common/connectivity/connectivity_controller.dart +++ b/lib/features/common/connectivity/connectivity_controller.dart @@ -17,7 +17,7 @@ class ConnectivityController extends _$ConnectivityController with AppLogger { activeProfileProvider.select((value) => value.asData?.value), (previous, next) async { if (previous == null) return; - final shouldReconnect = previous != next; + final shouldReconnect = next == null || previous.id != next.id; if (shouldReconnect) { await reconnect(next?.id); } diff --git a/lib/features/profiles/notifier/profiles_notifier.dart b/lib/features/profiles/notifier/profiles_notifier.dart index 684c1bcc..87266d2a 100644 --- a/lib/features/profiles/notifier/profiles_notifier.dart +++ b/lib/features/profiles/notifier/profiles_notifier.dart @@ -6,6 +6,7 @@ import 'package:hiddify/data/data_providers.dart'; import 'package:hiddify/domain/enums.dart'; import 'package:hiddify/domain/profiles/profiles.dart'; import 'package:hiddify/features/common/active_profile/active_profile_notifier.dart'; +import 'package:hiddify/features/common/connectivity/connectivity_controller.dart'; import 'package:hiddify/utils/utils.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -86,15 +87,23 @@ class ProfilesNotifier extends _$ProfilesNotifier with AppLogger { Future updateProfile(RemoteProfile profile) async { loggy.debug("updating profile"); - return ref.read(profilesRepositoryProvider).update(profile).match( + return await ref.read(profilesRepositoryProvider).update(profile).match( (err) { loggy.warning("failed to update profile", err); throw err; }, - (_) { + (_) async { loggy.info( 'successfully updated profile, was active? [${profile.active}]', ); + + await ref.read(activeProfileProvider.future).then((active) async { + if (active != null && active.id == profile.id) { + await ref + .read(connectivityControllerProvider.notifier) + .reconnect(profile.id); + } + }); return unit; }, ).run();