Refactor preferences
This commit is contained in:
@@ -15,8 +15,7 @@ ConnectionRepository connectionRepository(
|
||||
) {
|
||||
return ConnectionRepositoryImpl(
|
||||
directories: ref.watch(appDirectoriesProvider).requireValue,
|
||||
singBoxConfigOptionRepository:
|
||||
ref.watch(singBoxConfigOptionRepositoryProvider),
|
||||
configOptionRepository: ref.watch(configOptionRepositoryProvider),
|
||||
singbox: ref.watch(singboxServiceProvider),
|
||||
platformSource: ConnectionPlatformSourceImpl(),
|
||||
profilePathResolver: ref.watch(profilePathResolverProvider),
|
||||
|
||||
@@ -38,7 +38,7 @@ class ConnectionRepositoryImpl
|
||||
required this.directories,
|
||||
required this.singbox,
|
||||
required this.platformSource,
|
||||
required this.singBoxConfigOptionRepository,
|
||||
required this.configOptionRepository,
|
||||
required this.profilePathResolver,
|
||||
required this.geoAssetPathResolver,
|
||||
});
|
||||
@@ -46,7 +46,7 @@ class ConnectionRepositoryImpl
|
||||
final Directories directories;
|
||||
final SingboxService singbox;
|
||||
final ConnectionPlatformSource platformSource;
|
||||
final SingBoxConfigOptionRepository singBoxConfigOptionRepository;
|
||||
final ConfigOptionRepository configOptionRepository;
|
||||
final ProfilePathResolver profilePathResolver;
|
||||
final GeoAssetPathResolver geoAssetPathResolver;
|
||||
|
||||
@@ -83,7 +83,7 @@ class ConnectionRepositoryImpl
|
||||
return TaskEither<ConnectionFailure, SingboxConfigOption>.Do(
|
||||
($) async {
|
||||
final options = await $(
|
||||
singBoxConfigOptionRepository
|
||||
configOptionRepository
|
||||
.getFullSingboxConfigOption()
|
||||
.mapLeft((l) => const InvalidConfigOption()),
|
||||
);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user