From 4b8ea0f375947903acde1952ed3acc13b0361add Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sun, 18 Feb 2024 18:24:42 +0330 Subject: [PATCH] Add more haptic feedback --- lib/core/haptic/haptic_service.dart | 6 ++++++ .../connection/notifier/connection_notifier.dart | 11 +++++++++++ .../profile/overview/profiles_overview_notifier.dart | 2 ++ lib/features/proxy/active/ip_widget.dart | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/lib/core/haptic/haptic_service.dart b/lib/core/haptic/haptic_service.dart index 2015a1a7..99e8d39a 100644 --- a/lib/core/haptic/haptic_service.dart +++ b/lib/core/haptic/haptic_service.dart @@ -32,4 +32,10 @@ class HapticService extends _$HapticService { await HapticFeedback.mediumImpact(); } } + + Future heavyImpact() async { + if (state) { + await HapticFeedback.heavyImpact(); + } + } } diff --git a/lib/features/connection/notifier/connection_notifier.dart b/lib/features/connection/notifier/connection_notifier.dart index 9111bb62..0c44a0e4 100644 --- a/lib/features/connection/notifier/connection_notifier.dart +++ b/lib/features/connection/notifier/connection_notifier.dart @@ -25,6 +25,17 @@ class ConnectionNotifier extends _$ConnectionNotifier with AppLogger { }).run(); } + ref.listenSelf( + (previous, next) async { + if (previous == next) return; + if (previous case AsyncData(:final value) when !value.isConnected) { + if (next case AsyncData(value: final Connected _)) { + await ref.read(hapticServiceProvider.notifier).heavyImpact(); + } + } + }, + ); + ref.listen( activeProfileProvider.select((value) => value.asData?.value), (previous, next) async { diff --git a/lib/features/profile/overview/profiles_overview_notifier.dart b/lib/features/profile/overview/profiles_overview_notifier.dart index 7dcc68d4..2839c196 100644 --- a/lib/features/profile/overview/profiles_overview_notifier.dart +++ b/lib/features/profile/overview/profiles_overview_notifier.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'package:fpdart/fpdart.dart'; +import 'package:hiddify/core/haptic/haptic_service.dart'; import 'package:hiddify/features/profile/data/profile_data_providers.dart'; import 'package:hiddify/features/profile/data/profile_repository.dart'; import 'package:hiddify/features/profile/model/profile_entity.dart'; @@ -46,6 +47,7 @@ class ProfilesOverviewNotifier extends _$ProfilesOverviewNotifier Future selectActiveProfile(String id) async { loggy.debug('changing active profile to: [$id]'); + await ref.read(hapticServiceProvider.notifier).lightImpact(); return _profilesRepo.setAsActive(id).getOrElse((err) { loggy.warning('failed to set [$id] as active profile', err); throw err; diff --git a/lib/features/proxy/active/ip_widget.dart b/lib/features/proxy/active/ip_widget.dart index f16d0c1f..40b4431a 100644 --- a/lib/features/proxy/active/ip_widget.dart +++ b/lib/features/proxy/active/ip_widget.dart @@ -1,5 +1,6 @@ import 'package:circle_flags/circle_flags.dart'; import 'package:flutter/material.dart'; +import 'package:hiddify/core/haptic/haptic_service.dart'; import 'package:hiddify/core/localization/translations.dart'; import 'package:hiddify/core/utils/ip_utils.dart'; import 'package:hiddify/utils/riverpod_utils.dart'; @@ -7,6 +8,11 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; final _showIp = StateProvider.autoDispose((ref) { ref.disposeDelay(const Duration(seconds: 20)); + ref.listenSelf((previous, next) { + if (previous == false && next == true) { + ref.read(hapticServiceProvider.notifier).mediumImpact(); + } + }); return false; });