Change mark new profile active

This commit is contained in:
problematicconsumer
2023-09-10 14:16:44 +03:30
parent 7920cb7c06
commit 830a5cd75f
3 changed files with 27 additions and 3 deletions

View File

@@ -31,3 +31,20 @@ class DebugModeNotifier extends _$DebugModeNotifier {
return _pref.update(value);
}
}
@riverpod
class MarkNewProfileActive extends _$MarkNewProfileActive {
late final _pref = Pref(
ref.watch(sharedPreferencesProvider),
"mark_new_profile_active",
true,
);
@override
bool build() => _pref.getValue();
Future<void> update(bool value) {
state = value;
return _pref.update(value);
}
}

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/core/router/routes/routes.dart';
@@ -32,6 +33,9 @@ class ProfileTile extends HookConsumerWidget {
initialOnFailure: (err) {
CustomToast.error(t.printError(err)).show(context);
},
initialOnSuccess: () {
if (context.mounted) context.pop();
},
);
final subInfo = profile.subInfo;

View File

@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:fpdart/fpdart.dart';
import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/enums.dart';
import 'package:hiddify/domain/profiles/profiles.dart';
@@ -40,9 +41,9 @@ class ProfilesNotifier extends _$ProfilesNotifier with AppLogger {
ProfilesRepository get _profilesRepo => ref.read(profilesRepositoryProvider);
Future<void> selectActiveProfile(String id) async {
Future<Unit> selectActiveProfile(String id) async {
loggy.debug('changing active profile to: [$id]');
await _profilesRepo.setAsActive(id).mapLeft((f) {
return _profilesRepo.setAsActive(id).getOrElse((f) {
loggy.warning('failed to set [$id] as active profile, $f');
throw f;
}).run();
@@ -50,10 +51,12 @@ class ProfilesNotifier extends _$ProfilesNotifier with AppLogger {
Future<Unit> addProfile(String url) async {
final activeProfile = await ref.read(activeProfileProvider.future);
final markAsActive =
activeProfile == null || ref.read(markNewProfileActiveProvider);
loggy.debug("adding profile, url: [$url]");
return ref
.read(profilesRepositoryProvider)
.addByUrl(url, markAsActive: activeProfile == null)
.addByUrl(url, markAsActive: markAsActive)
.getOrElse((l) {
loggy.warning("failed to add profile: $l");
throw l;