Add local profile

This commit is contained in:
problematicconsumer
2023-10-02 18:51:14 +03:30
parent a7e157c036
commit d50541f7a3
26 changed files with 1118 additions and 260 deletions

View File

@@ -1,4 +1,3 @@
import 'package:fpdart/fpdart.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/profiles/profiles.dart';
import 'package:hiddify/utils/utils.dart';
@@ -16,16 +15,4 @@ class ActiveProfile extends _$ActiveProfile with AppLogger {
.watchActiveProfile()
.map((event) => event.getOrElse((l) => throw l));
}
Future<Unit?> updateProfile() async {
if (state case AsyncData(value: final profile?)) {
loggy.debug("updating active profile");
return ref
.read(profilesRepositoryProvider)
.update(profile)
.getOrElse((l) => throw l)
.run();
}
return null;
}
}

View File

@@ -39,7 +39,10 @@ class ProfileTile extends HookConsumerWidget {
},
);
final subInfo = profile.subInfo;
final subInfo = switch (profile) {
RemoteProfile(:final subInfo) => subInfo,
_ => null,
};
final effectiveMargin = isMain
? const EdgeInsets.symmetric(horizontal: 16, vertical: 8)
@@ -60,17 +63,19 @@ class ProfileTile extends HookConsumerWidget {
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
width: 48,
child: Semantics(
sortKey: const OrdinalSortKey(1),
child: ProfileActionButton(profile, !isMain),
if (profile is RemoteProfile || !isMain) ...[
SizedBox(
width: 48,
child: Semantics(
sortKey: const OrdinalSortKey(1),
child: ProfileActionButton(profile, !isMain),
),
),
),
VerticalDivider(
width: 1,
color: effectiveOutlineColor,
),
VerticalDivider(
width: 1,
color: effectiveOutlineColor,
),
],
Expanded(
child: Semantics(
button: true,
@@ -177,7 +182,7 @@ class ProfileActionButton extends HookConsumerWidget {
CustomToast.success(t.profile.update.successMsg).show(context),
);
if (!showAllActions) {
if (profile case RemoteProfile() when !showAllActions) {
return Semantics(
button: true,
enabled: !updateProfileMutation.state.isInProgress,
@@ -191,7 +196,7 @@ class ProfileActionButton extends HookConsumerWidget {
updateProfileMutation.setFuture(
ref
.read(profilesNotifierProvider.notifier)
.updateProfile(profile),
.updateProfile(profile as RemoteProfile),
);
},
child: const Icon(Icons.update),
@@ -250,20 +255,21 @@ class ProfileActionsMenu extends HookConsumerWidget {
return MenuAnchor(
builder: builder,
menuChildren: [
MenuItemButton(
leadingIcon: const Icon(Icons.update),
child: Text(t.profile.update.buttonTxt),
onPressed: () {
if (updateProfileMutation.state.isInProgress) {
return;
}
updateProfileMutation.setFuture(
ref
.read(profilesNotifierProvider.notifier)
.updateProfile(profile),
);
},
),
if (profile case RemoteProfile())
MenuItemButton(
leadingIcon: const Icon(Icons.update),
child: Text(t.profile.update.buttonTxt),
onPressed: () {
if (updateProfileMutation.state.isInProgress) {
return;
}
updateProfileMutation.setFuture(
ref
.read(profilesNotifierProvider.notifier)
.updateProfile(profile as RemoteProfile),
);
},
),
MenuItemButton(
leadingIcon: const Icon(Icons.edit),
child: Text(t.profile.edit.buttonTxt),