Add more haptic feedback

This commit is contained in:
problematicconsumer
2024-02-18 18:24:42 +03:30
parent c402a9e292
commit 4b8ea0f375
4 changed files with 25 additions and 0 deletions

View File

@@ -32,4 +32,10 @@ class HapticService extends _$HapticService {
await HapticFeedback.mediumImpact();
}
}
Future<void> heavyImpact() async {
if (state) {
await HapticFeedback.heavyImpact();
}
}
}

View File

@@ -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 {

View File

@@ -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<Unit> 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;

View File

@@ -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;
});