Refactor preferences

This commit is contained in:
problematicconsumer
2024-03-02 22:53:14 +03:30
parent 201ea5e88d
commit 2a994dc348
32 changed files with 1104 additions and 1389 deletions

View File

@@ -2,7 +2,6 @@ import 'dart:io';
import 'package:hiddify/core/haptic/haptic_service.dart';
import 'package:hiddify/core/preferences/general_preferences.dart';
import 'package:hiddify/core/preferences/service_preferences.dart';
import 'package:hiddify/features/connection/data/connection_data_providers.dart';
import 'package:hiddify/features/connection/data/connection_repository.dart';
import 'package:hiddify/features/connection/model/connection_status.dart';
@@ -49,7 +48,7 @@ class ConnectionNotifier extends _$ConnectionNotifier with AppLogger {
yield* _connectionRepo.watchConnectionStatus().doOnData((event) {
if (event case Disconnected(connectionFailure: final _?)
when PlatformUtils.isDesktop) {
ref.read(startedByUserProvider.notifier).update(false);
ref.read(Preferences.startedByUser.notifier).update(false);
}
loggy.info("connection status: ${event.format()}");
});
@@ -73,11 +72,11 @@ class ConnectionNotifier extends _$ConnectionNotifier with AppLogger {
switch (value) {
case Disconnected():
await haptic.lightImpact();
await ref.read(startedByUserProvider.notifier).update(true);
await ref.read(Preferences.startedByUser.notifier).update(true);
await _connect();
case Connected():
await haptic.mediumImpact();
await ref.read(startedByUserProvider.notifier).update(false);
await ref.read(Preferences.startedByUser.notifier).update(false);
await _disconnect();
default:
loggy.warning("switching status, debounce");
@@ -92,12 +91,12 @@ class ConnectionNotifier extends _$ConnectionNotifier with AppLogger {
return _disconnect();
}
loggy.info("active profile changed, reconnecting");
await ref.read(startedByUserProvider.notifier).update(true);
await ref.read(Preferences.startedByUser.notifier).update(true);
await _connectionRepo
.reconnect(
profile.id,
profile.name,
ref.read(disableMemoryLimitProvider),
ref.read(Preferences.disableMemoryLimit),
)
.mapLeft((err) {
loggy.warning("error reconnecting", err);
@@ -127,7 +126,7 @@ class ConnectionNotifier extends _$ConnectionNotifier with AppLogger {
.connect(
activeProfile.id,
activeProfile.name,
ref.read(disableMemoryLimitProvider),
ref.read(Preferences.disableMemoryLimit),
)
.mapLeft((err) async {
loggy.warning("error connecting", err);
@@ -136,7 +135,7 @@ class ConnectionNotifier extends _$ConnectionNotifier with AppLogger {
if (err.toString().contains("panic")) {
await Sentry.captureException(Exception(err.toString()));
}
await ref.read(startedByUserProvider.notifier).update(false);
await ref.read(Preferences.startedByUser.notifier).update(false);
state = AsyncError(err, StackTrace.current);
}).run();
}