new: add json editor and editing configs <3
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -28,6 +28,7 @@ env:
|
|||||||
TARGET_NAME_dmg: "Hiddify-MacOS"
|
TARGET_NAME_dmg: "Hiddify-MacOS"
|
||||||
TARGET_NAME_pkg: "Hiddify-MacOS-Installer"
|
TARGET_NAME_pkg: "Hiddify-MacOS-Installer"
|
||||||
TARGET_NAME_ipa: "Hiddify-iOS"
|
TARGET_NAME_ipa: "Hiddify-iOS"
|
||||||
|
TARGET_NAME_ipa2: "Hiddify-iOS2"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -91,6 +92,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Import Apple Codesign Certificates
|
- name: Import Apple Codesign Certificates
|
||||||
if: ${{ inputs.upload-artifact && startsWith(matrix.os,'macos') }}
|
if: ${{ inputs.upload-artifact && startsWith(matrix.os,'macos') }}
|
||||||
uses: apple-actions/import-codesign-certs@v3
|
uses: apple-actions/import-codesign-certs@v3
|
||||||
@@ -103,7 +105,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
|
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
|
||||||
echo "${{secrets.NEW_APPLE_MOBILE_PROVISIONING_PROFILES_TARGZ_BASE64}}"|base64 --decode | tar xJ -C ~/Library/MobileDevice/Provisioning\ Profiles
|
echo "${{secrets.NEW_APPLE_MOBILE_PROVISIONING_PROFILES_TARGZ_BASE64}}"|base64 --decode | tar xJ -C ~/Library/MobileDevice/Provisioning\ Profiles
|
||||||
ls ~/Library/MobileDevice/Provisioning\ Profiles
|
|
||||||
# # echo "${{secrets.NEW_APPLE_MOBILE_PROVISIONING_PROFILES_TARGZ_BASE64_2}}"|base64 --decode | tar xz -C ~/Library/MobileDevice/Provisioning\ Profiles
|
# # echo "${{secrets.NEW_APPLE_MOBILE_PROVISIONING_PROFILES_TARGZ_BASE64_2}}"|base64 --decode | tar xz -C ~/Library/MobileDevice/Provisioning\ Profiles
|
||||||
# # echo "${{secrets.APPLE_DEVLOP_PROVISIONING_PROFILES_TARGZ_BASE64}}"|base64 --decode | tar xz -C ~/Library/MobileDevice/Provisioning\ Profiles
|
# # echo "${{secrets.APPLE_DEVLOP_PROVISIONING_PROFILES_TARGZ_BASE64}}"|base64 --decode | tar xz -C ~/Library/MobileDevice/Provisioning\ Profiles
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'package:hiddify/core/database/database_provider.dart';
|
import 'package:hiddify/core/database/database_provider.dart';
|
||||||
import 'package:hiddify/core/directories/directories_provider.dart';
|
import 'package:hiddify/core/directories/directories_provider.dart';
|
||||||
import 'package:hiddify/core/http_client/http_client_provider.dart';
|
import 'package:hiddify/core/http_client/http_client_provider.dart';
|
||||||
|
import 'package:hiddify/features/config_option/data/config_option_data_providers.dart';
|
||||||
|
import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_data_source.dart';
|
import 'package:hiddify/features/profile/data/profile_data_source.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_path_resolver.dart';
|
import 'package:hiddify/features/profile/data/profile_path_resolver.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_repository.dart';
|
import 'package:hiddify/features/profile/data/profile_repository.dart';
|
||||||
@@ -15,6 +17,7 @@ Future<ProfileRepository> profileRepository(ProfileRepositoryRef ref) async {
|
|||||||
profileDataSource: ref.watch(profileDataSourceProvider),
|
profileDataSource: ref.watch(profileDataSourceProvider),
|
||||||
profilePathResolver: ref.watch(profilePathResolverProvider),
|
profilePathResolver: ref.watch(profilePathResolverProvider),
|
||||||
singbox: ref.watch(singboxServiceProvider),
|
singbox: ref.watch(singboxServiceProvider),
|
||||||
|
configOptionRepository: ref.watch(configOptionRepositoryProvider),
|
||||||
httpClient: ref.watch(httpClientProvider),
|
httpClient: ref.watch(httpClientProvider),
|
||||||
);
|
);
|
||||||
await repo.init().getOrElse((l) => throw l).run();
|
await repo.init().getOrElse((l) => throw l).run();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import 'package:fpdart/fpdart.dart';
|
|||||||
import 'package:hiddify/core/database/app_database.dart';
|
import 'package:hiddify/core/database/app_database.dart';
|
||||||
import 'package:hiddify/core/http_client/dio_http_client.dart';
|
import 'package:hiddify/core/http_client/dio_http_client.dart';
|
||||||
import 'package:hiddify/core/utils/exception_handler.dart';
|
import 'package:hiddify/core/utils/exception_handler.dart';
|
||||||
|
import 'package:hiddify/features/config_option/data/config_option_repository.dart';
|
||||||
|
import 'package:hiddify/features/connection/model/connection_failure.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_data_mapper.dart';
|
import 'package:hiddify/features/profile/data/profile_data_mapper.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_data_source.dart';
|
import 'package:hiddify/features/profile/data/profile_data_source.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_parser.dart';
|
import 'package:hiddify/features/profile/data/profile_parser.dart';
|
||||||
@@ -36,7 +38,10 @@ abstract interface class ProfileRepository {
|
|||||||
bool markAsActive = false,
|
bool markAsActive = false,
|
||||||
CancelToken? cancelToken,
|
CancelToken? cancelToken,
|
||||||
});
|
});
|
||||||
|
TaskEither<ProfileFailure, Unit> updateContent(
|
||||||
|
String profileId,
|
||||||
|
String content,
|
||||||
|
);
|
||||||
TaskEither<ProfileFailure, Unit> addByContent(
|
TaskEither<ProfileFailure, Unit> addByContent(
|
||||||
String content, {
|
String content, {
|
||||||
required String name,
|
required String name,
|
||||||
@@ -67,12 +72,14 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
|||||||
required this.profileDataSource,
|
required this.profileDataSource,
|
||||||
required this.profilePathResolver,
|
required this.profilePathResolver,
|
||||||
required this.singbox,
|
required this.singbox,
|
||||||
|
required this.configOptionRepository,
|
||||||
required this.httpClient,
|
required this.httpClient,
|
||||||
});
|
});
|
||||||
|
|
||||||
final ProfileDataSource profileDataSource;
|
final ProfileDataSource profileDataSource;
|
||||||
final ProfilePathResolver profilePathResolver;
|
final ProfilePathResolver profilePathResolver;
|
||||||
final SingboxService singbox;
|
final SingboxService singbox;
|
||||||
|
final ConfigOptionRepository configOptionRepository;
|
||||||
final DioHttpClient httpClient;
|
final DioHttpClient httpClient;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -177,6 +184,30 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
TaskEither<ProfileFailure, Unit> updateContent(
|
||||||
|
String profileId,
|
||||||
|
String content,
|
||||||
|
) {
|
||||||
|
return exceptionHandler(
|
||||||
|
() async {
|
||||||
|
final file = profilePathResolver.file(profileId);
|
||||||
|
final tempFile = profilePathResolver.tempFile(profileId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await tempFile.writeAsString(content);
|
||||||
|
return await validateConfig(file.path, tempFile.path, false).run();
|
||||||
|
} finally {
|
||||||
|
if (tempFile.existsSync()) tempFile.deleteSync();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error, stackTrace) {
|
||||||
|
loggy.warning("error adding profile by content", error, stackTrace);
|
||||||
|
return ProfileUnexpectedFailure(error, stackTrace);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TaskEither<ProfileFailure, Unit> addByContent(
|
TaskEither<ProfileFailure, Unit> addByContent(
|
||||||
String content, {
|
String content, {
|
||||||
@@ -186,12 +217,8 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
|||||||
return exceptionHandler(
|
return exceptionHandler(
|
||||||
() async {
|
() async {
|
||||||
final profileId = const Uuid().v4();
|
final profileId = const Uuid().v4();
|
||||||
final file = profilePathResolver.file(profileId);
|
|
||||||
final tempFile = profilePathResolver.tempFile(profileId);
|
|
||||||
|
|
||||||
try {
|
return await updateContent(profileId, content)
|
||||||
await tempFile.writeAsString(content);
|
|
||||||
return await validateConfig(file.path, tempFile.path, false)
|
|
||||||
.andThen(
|
.andThen(
|
||||||
() => TaskEither(() async {
|
() => TaskEither(() async {
|
||||||
final profile = LocalProfileEntity(
|
final profile = LocalProfileEntity(
|
||||||
@@ -201,13 +228,11 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
|||||||
lastUpdate: DateTime.now(),
|
lastUpdate: DateTime.now(),
|
||||||
);
|
);
|
||||||
await profileDataSource.insert(profile.toEntry());
|
await profileDataSource.insert(profile.toEntry());
|
||||||
|
|
||||||
return right(unit);
|
return right(unit);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
} finally {
|
|
||||||
if (tempFile.existsSync()) tempFile.deleteSync();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(error, stackTrace) {
|
(error, stackTrace) {
|
||||||
loggy.warning("error adding profile by content", error, stackTrace);
|
loggy.warning("error adding profile by content", error, stackTrace);
|
||||||
@@ -252,6 +277,10 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
|
|||||||
($) async {
|
($) async {
|
||||||
final configFile = profilePathResolver.file(id);
|
final configFile = profilePathResolver.file(id);
|
||||||
// TODO pass options
|
// TODO pass options
|
||||||
|
final options = await configOptionRepository.getConfigOptions();
|
||||||
|
|
||||||
|
singbox.changeOptions(options).mapLeft(InvalidConfigOption.new).run();
|
||||||
|
|
||||||
return await $(
|
return await $(
|
||||||
singbox.generateFullConfigByPath(configFile.path).mapLeft(ProfileFailure.unexpected),
|
singbox.generateFullConfigByPath(configFile.path).mapLeft(ProfileFailure.unexpected),
|
||||||
);
|
);
|
||||||
|
|||||||
1330
lib/features/profile/details/json_editor.dart
Normal file
1330
lib/features/profile/details/json_editor.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:dartx/dartx.dart';
|
import 'package:dartx/dartx.dart';
|
||||||
import 'package:fpdart/fpdart.dart';
|
import 'package:fpdart/fpdart.dart';
|
||||||
import 'package:hiddify/features/profile/data/profile_data_providers.dart';
|
import 'package:hiddify/features/profile/data/profile_data_providers.dart';
|
||||||
@@ -36,22 +38,53 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
|||||||
loggy.warning('failed to load profile', err);
|
loggy.warning('failed to load profile', err);
|
||||||
throw err;
|
throw err;
|
||||||
},
|
},
|
||||||
(profile) {
|
(profile) async {
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
loggy.warning('profile with id: [$id] does not exist');
|
loggy.warning('profile with id: [$id] does not exist');
|
||||||
throw const ProfileNotFoundFailure();
|
throw const ProfileNotFoundFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
_originalProfile = profile;
|
_originalProfile = profile;
|
||||||
return ProfileDetailsState(profile: profile, isEditing: true);
|
final result = await _profilesRepo.generateConfig(id).run();
|
||||||
|
|
||||||
|
var configContent = result.fold(
|
||||||
|
(failure) => throw Exception('Failed to generate config: $failure'),
|
||||||
|
(config) => config,
|
||||||
|
);
|
||||||
|
if (configContent.isNotEmpty) {
|
||||||
|
try {
|
||||||
|
final jsonObject = jsonDecode(configContent);
|
||||||
|
List<Map<String, dynamic>> res = [];
|
||||||
|
if (jsonObject is Map<String, dynamic> && jsonObject['outbounds'] is List) {
|
||||||
|
for (var outbound in jsonObject['outbounds'] as List<dynamic>) {
|
||||||
|
if (outbound is Map<String, dynamic> && outbound['type'] != null && !['selector', 'urltest', 'dns', 'block'].contains(outbound['type']) && !['direct', 'bypass', 'direct-fragment'].contains(outbound['tag'])) {
|
||||||
|
res.add(outbound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// print('No outbounds found in the config');
|
||||||
|
}
|
||||||
|
configContent = '{"outbounds": ${json.encode(res)}}';
|
||||||
|
} catch (e) {
|
||||||
|
// print('Error parsing JSON: $e');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// print('Config content is null or empty');
|
||||||
|
}
|
||||||
|
return ProfileDetailsState(profile: profile, isEditing: true, configContent: configContent);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileRepository get _profilesRepo =>
|
ProfileRepository get _profilesRepo => ref.read(profileRepositoryProvider).requireValue;
|
||||||
ref.read(profileRepositoryProvider).requireValue;
|
|
||||||
ProfileEntity? _originalProfile;
|
ProfileEntity? _originalProfile;
|
||||||
|
|
||||||
void setField({String? name, String? url, Option<int>? updateInterval}) {
|
void setField({
|
||||||
|
String? name,
|
||||||
|
String? url,
|
||||||
|
Option<int>? updateInterval,
|
||||||
|
String? configContent,
|
||||||
|
}) {
|
||||||
if (state case AsyncData(:final value)) {
|
if (state case AsyncData(:final value)) {
|
||||||
state = AsyncData(
|
state = AsyncData(
|
||||||
value.copyWith(
|
value.copyWith(
|
||||||
@@ -70,6 +103,8 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
|||||||
),
|
),
|
||||||
local: (lp) => lp.copyWith(name: name ?? lp.name),
|
local: (lp) => lp.copyWith(name: name ?? lp.name),
|
||||||
),
|
),
|
||||||
|
configContentChanged: value.configContentChanged || value.configContent != configContent,
|
||||||
|
configContent: configContent ?? value.configContent,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -91,16 +126,29 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
|||||||
if (profile.name.isBlank || profile.url.isBlank) {
|
if (profile.name.isBlank || profile.url.isBlank) {
|
||||||
loggy.debug('save: invalid arguments');
|
loggy.debug('save: invalid arguments');
|
||||||
} else if (value.isEditing) {
|
} else if (value.isEditing) {
|
||||||
if (_originalProfile case RemoteProfileEntity(:final url)
|
if (_originalProfile case RemoteProfileEntity(:final url) when url == profile.url) {
|
||||||
when url == profile.url) {
|
|
||||||
loggy.debug('editing profile');
|
loggy.debug('editing profile');
|
||||||
failureOrSuccess = await _profilesRepo.patch(profile).run();
|
failureOrSuccess = await _profilesRepo.patch(profile).run();
|
||||||
|
if (failureOrSuccess.isRight()) {
|
||||||
|
failureOrSuccess = await _profilesRepo
|
||||||
|
.updateContent(
|
||||||
|
profile.id,
|
||||||
|
value.configContent,
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
loggy.debug('updating profile');
|
loggy.debug('updating profile');
|
||||||
|
failureOrSuccess = await _profilesRepo.updateSubscription(profile, patchBaseProfile: true).run();
|
||||||
|
if (failureOrSuccess.isRight()) {
|
||||||
failureOrSuccess = await _profilesRepo
|
failureOrSuccess = await _profilesRepo
|
||||||
.updateSubscription(profile, patchBaseProfile: true)
|
.updateContent(
|
||||||
|
profile.id,
|
||||||
|
value.configContent,
|
||||||
|
)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
loggy.debug('adding profile, url: [${profile.url}]');
|
loggy.debug('adding profile, url: [${profile.url}]');
|
||||||
failureOrSuccess = await _profilesRepo.add(profile).run();
|
failureOrSuccess = await _profilesRepo.add(profile).run();
|
||||||
@@ -138,10 +186,7 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
|||||||
final profile = value.profile;
|
final profile = value.profile;
|
||||||
state = AsyncData(value.copyWith(update: const AsyncLoading()));
|
state = AsyncData(value.copyWith(update: const AsyncLoading()));
|
||||||
|
|
||||||
final failureOrUpdatedProfile = await _profilesRepo
|
final failureOrUpdatedProfile = await _profilesRepo.updateSubscription(profile as RemoteProfileEntity).flatMap((_) => _profilesRepo.getById(id)).run();
|
||||||
.updateSubscription(profile as RemoteProfileEntity)
|
|
||||||
.flatMap((_) => _profilesRepo.getById(id))
|
|
||||||
.run();
|
|
||||||
|
|
||||||
state = AsyncData(
|
state = AsyncData(
|
||||||
value.copyWith(
|
value.copyWith(
|
||||||
@@ -167,10 +212,7 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
|
|||||||
state = AsyncData(
|
state = AsyncData(
|
||||||
value.copyWith(
|
value.copyWith(
|
||||||
delete: await AsyncValue.guard(() async {
|
delete: await AsyncValue.guard(() async {
|
||||||
await _profilesRepo
|
await _profilesRepo.deleteById(profile.id).getOrElse((l) => throw l).run();
|
||||||
.deleteById(profile.id)
|
|
||||||
.getOrElse((l) => throw l)
|
|
||||||
.run();
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fpdart/fpdart.dart';
|
import 'package:fpdart/fpdart.dart';
|
||||||
@@ -7,12 +9,17 @@ import 'package:hiddify/core/localization/translations.dart';
|
|||||||
import 'package:hiddify/core/model/failures.dart';
|
import 'package:hiddify/core/model/failures.dart';
|
||||||
import 'package:hiddify/core/widget/adaptive_icon.dart';
|
import 'package:hiddify/core/widget/adaptive_icon.dart';
|
||||||
import 'package:hiddify/features/common/confirmation_dialogs.dart';
|
import 'package:hiddify/features/common/confirmation_dialogs.dart';
|
||||||
|
import 'package:hiddify/features/profile/details/json_editor.dart';
|
||||||
import 'package:hiddify/features/profile/details/profile_details_notifier.dart';
|
import 'package:hiddify/features/profile/details/profile_details_notifier.dart';
|
||||||
import 'package:hiddify/features/profile/model/profile_entity.dart';
|
import 'package:hiddify/features/profile/model/profile_entity.dart';
|
||||||
import 'package:hiddify/features/settings/widgets/widgets.dart';
|
import 'package:hiddify/features/settings/widgets/widgets.dart';
|
||||||
import 'package:hiddify/utils/utils.dart';
|
import 'package:hiddify/utils/utils.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:humanizer/humanizer.dart';
|
import 'package:humanizer/humanizer.dart';
|
||||||
|
// import 'package:lucy_editor/lucy_editor.dart';
|
||||||
|
// import 'package:re_highlight/languages/json.dart';
|
||||||
|
// import 'package:re_highlight/styles/atom-one-light.dart';
|
||||||
|
// import 'package:json_editor_flutter/json_editor_flutter.dart';
|
||||||
|
|
||||||
class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
||||||
const ProfileDetailsPage(this.id, {super.key});
|
const ProfileDetailsPage(this.id, {super.key});
|
||||||
@@ -39,14 +46,12 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
);
|
);
|
||||||
case AsyncError(:final error):
|
case AsyncError(:final error):
|
||||||
final String action;
|
final String action;
|
||||||
if (ref.read(provider) case AsyncData(value: final data)
|
if (ref.read(provider) case AsyncData(value: final data) when data.isEditing) {
|
||||||
when data.isEditing) {
|
|
||||||
action = t.profile.save.failureMsg;
|
action = t.profile.save.failureMsg;
|
||||||
} else {
|
} else {
|
||||||
action = t.profile.add.failureMsg;
|
action = t.profile.add.failureMsg;
|
||||||
}
|
}
|
||||||
CustomAlertDialog.fromErr(t.presentError(error, action: action))
|
CustomAlertDialog.fromErr(t.presentError(error, action: action)).show(context);
|
||||||
.show(context);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -82,9 +87,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
|
|
||||||
switch (ref.watch(provider)) {
|
switch (ref.watch(provider)) {
|
||||||
case AsyncData(value: final state):
|
case AsyncData(value: final state):
|
||||||
final showLoadingOverlay = state.isBusy ||
|
final showLoadingOverlay = state.isBusy || state.save is MutationSuccess || state.delete is MutationSuccess;
|
||||||
state.save is MutationSuccess ||
|
|
||||||
state.delete is MutationSuccess;
|
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
@@ -96,6 +99,16 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
title: Text(t.profile.detailsPageTitle),
|
title: Text(t.profile.detailsPageTitle),
|
||||||
pinned: true,
|
pinned: true,
|
||||||
actions: [
|
actions: [
|
||||||
|
// MenuItemButton(
|
||||||
|
// onPressed: context.pop,
|
||||||
|
// child: Text(
|
||||||
|
// MaterialLocalizations.of(context).cancelButtonLabel,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
MenuItemButton(
|
||||||
|
onPressed: notifier.save,
|
||||||
|
child: Text(t.profile.save.buttonText),
|
||||||
|
),
|
||||||
if (state.isEditing)
|
if (state.isEditing)
|
||||||
PopupMenuButton(
|
PopupMenuButton(
|
||||||
icon: Icon(AdaptiveIcon(context).more),
|
icon: Icon(AdaptiveIcon(context).more),
|
||||||
@@ -111,8 +124,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: Text(t.profile.delete.buttonTxt),
|
child: Text(t.profile.delete.buttonTxt),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final deleteConfirmed =
|
final deleteConfirmed = await showConfirmationDialog(
|
||||||
await showConfirmationDialog(
|
|
||||||
context,
|
context,
|
||||||
title: t.profile.delete.buttonTxt,
|
title: t.profile.delete.buttonTxt,
|
||||||
message: t.profile.delete.confirmationMsg,
|
message: t.profile.delete.confirmationMsg,
|
||||||
@@ -129,9 +141,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
Form(
|
Form(
|
||||||
autovalidateMode: state.showErrorMessages
|
autovalidateMode: state.showErrorMessages ? AutovalidateMode.always : AutovalidateMode.disabled,
|
||||||
? AutovalidateMode.always
|
|
||||||
: AutovalidateMode.disabled,
|
|
||||||
child: SliverList.list(
|
child: SliverList.list(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
@@ -141,20 +151,13 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
),
|
),
|
||||||
child: CustomTextFormField(
|
child: CustomTextFormField(
|
||||||
initialValue: state.profile.name,
|
initialValue: state.profile.name,
|
||||||
onChanged: (value) =>
|
onChanged: (value) => notifier.setField(name: value),
|
||||||
notifier.setField(name: value),
|
validator: (value) => (value?.isEmpty ?? true) ? t.profile.detailsForm.emptyNameMsg : null,
|
||||||
validator: (value) => (value?.isEmpty ?? true)
|
|
||||||
? t.profile.detailsForm.emptyNameMsg
|
|
||||||
: null,
|
|
||||||
label: t.profile.detailsForm.nameLabel,
|
label: t.profile.detailsForm.nameLabel,
|
||||||
hint: t.profile.detailsForm.nameHint,
|
hint: t.profile.detailsForm.nameHint,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (state.profile
|
if (state.profile case RemoteProfileEntity(:final url, :final options)) ...[
|
||||||
case RemoteProfileEntity(
|
|
||||||
:final url,
|
|
||||||
:final options
|
|
||||||
)) ...[
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 16,
|
horizontal: 16,
|
||||||
@@ -162,12 +165,8 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
),
|
),
|
||||||
child: CustomTextFormField(
|
child: CustomTextFormField(
|
||||||
initialValue: url,
|
initialValue: url,
|
||||||
onChanged: (value) =>
|
onChanged: (value) => notifier.setField(url: value),
|
||||||
notifier.setField(url: value),
|
validator: (value) => (value != null && !isUrl(value)) ? t.profile.detailsForm.invalidUrlMsg : null,
|
||||||
validator: (value) =>
|
|
||||||
(value != null && !isUrl(value))
|
|
||||||
? t.profile.detailsForm.invalidUrlMsg
|
|
||||||
: null,
|
|
||||||
label: t.profile.detailsForm.urlLabel,
|
label: t.profile.detailsForm.urlLabel,
|
||||||
hint: t.profile.detailsForm.urlHint,
|
hint: t.profile.detailsForm.urlHint,
|
||||||
),
|
),
|
||||||
@@ -180,13 +179,10 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
) ??
|
) ??
|
||||||
t.general.toggle.disabled,
|
t.general.toggle.disabled,
|
||||||
),
|
),
|
||||||
leading:
|
leading: const Icon(FluentIcons.arrow_sync_24_regular),
|
||||||
const Icon(FluentIcons.arrow_sync_24_regular),
|
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final intervalInHours =
|
final intervalInHours = await SettingsInputDialog(
|
||||||
await SettingsInputDialog(
|
title: t.profile.detailsForm.updateIntervalDialogTitle,
|
||||||
title: t.profile.detailsForm
|
|
||||||
.updateIntervalDialogTitle,
|
|
||||||
initialValue: options?.updateInterval.inHours,
|
initialValue: options?.updateInterval.inHours,
|
||||||
optionalAction: (
|
optionalAction: (
|
||||||
t.general.state.disable,
|
t.general.state.disable,
|
||||||
@@ -205,17 +201,28 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
// Padding(
|
||||||
|
// padding: const EdgeInsets.symmetric(
|
||||||
|
// horizontal: 16,
|
||||||
|
// vertical: 8,
|
||||||
|
// ),
|
||||||
|
// child: CustomTextFormField(
|
||||||
|
// initialValue: state.configContent,
|
||||||
|
// // onChanged: (value) => notifier.setField(name: value),
|
||||||
|
// maxLines: 7,
|
||||||
|
// label: t.profile.detailsForm.configContentLabel,
|
||||||
|
// hint: t.profile.detailsForm.configContentHint,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
if (state.isEditing) ...[
|
if (state.isEditing) ...[
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(t.profile.detailsForm.lastUpdate),
|
title: Text(t.profile.detailsForm.lastUpdate),
|
||||||
leading:
|
leading: const Icon(FluentIcons.history_24_regular),
|
||||||
const Icon(FluentIcons.history_24_regular),
|
|
||||||
subtitle: Text(state.profile.lastUpdate.format()),
|
subtitle: Text(state.profile.lastUpdate.format()),
|
||||||
dense: true,
|
dense: true,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
if (state.profile
|
if (state.profile case RemoteProfileEntity(:final subInfo?)) ...[
|
||||||
case RemoteProfileEntity(:final subInfo?)) ...[
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 18,
|
horizontal: 18,
|
||||||
@@ -225,8 +232,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text.rich(
|
Text.rich(
|
||||||
style:
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
Theme.of(context).textTheme.bodySmall,
|
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
_buildSubProp(
|
_buildSubProp(
|
||||||
@@ -242,8 +248,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
),
|
),
|
||||||
const TextSpan(text: " "),
|
const TextSpan(text: " "),
|
||||||
_buildSubProp(
|
_buildSubProp(
|
||||||
FluentIcons
|
FluentIcons.arrow_bidirectional_up_down_16_regular,
|
||||||
.arrow_bidirectional_up_down_16_regular,
|
|
||||||
subInfo.total.size(),
|
subInfo.total.size(),
|
||||||
t.profile.subscription.total,
|
t.profile.subscription.total,
|
||||||
),
|
),
|
||||||
@@ -252,8 +257,7 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
),
|
),
|
||||||
const Gap(12),
|
const Gap(12),
|
||||||
Text.rich(
|
Text.rich(
|
||||||
style:
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
Theme.of(context).textTheme.bodySmall,
|
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
_buildSubProp(
|
_buildSubProp(
|
||||||
@@ -268,41 +272,25 @@ class ProfileDetailsPage extends HookConsumerWidget with PresLogger {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
],
|
if (state.isEditing) ...[
|
||||||
|
SizedBox(
|
||||||
|
height: MediaQuery.of(context).size.height * 0.8,
|
||||||
|
child: JsonEditor(
|
||||||
|
expandedObjects: const ["outbounds"],
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value == null) return;
|
||||||
|
const encoder = const JsonEncoder.withIndent(' ');
|
||||||
|
|
||||||
|
notifier.setField(configContent: encoder.convert(value));
|
||||||
|
},
|
||||||
|
enableHorizontalScroll: true,
|
||||||
|
json: state.configContent,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SliverFillRemaining(
|
|
||||||
hasScrollBody: false,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16,
|
|
||||||
vertical: 16,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
OverflowBar(
|
|
||||||
spacing: 12,
|
|
||||||
overflowAlignment: OverflowBarAlignment.end,
|
|
||||||
children: [
|
|
||||||
OutlinedButton(
|
|
||||||
onPressed: context.pop,
|
|
||||||
child: Text(
|
|
||||||
MaterialLocalizations.of(context)
|
|
||||||
.cancelButtonLabel,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
onPressed: notifier.save,
|
|
||||||
child: Text(t.profile.save.buttonText),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ class ProfileDetailsState with _$ProfileDetailsState {
|
|||||||
AsyncValue<void>? save,
|
AsyncValue<void>? save,
|
||||||
AsyncValue<void>? update,
|
AsyncValue<void>? update,
|
||||||
AsyncValue<void>? delete,
|
AsyncValue<void>? delete,
|
||||||
|
@Default("") String configContent,
|
||||||
|
@Default(false) bool configContentChanged,
|
||||||
}) = _ProfileDetailsState;
|
}) = _ProfileDetailsState;
|
||||||
|
|
||||||
bool get isBusy =>
|
bool get isBusy => save is AsyncLoading || delete is AsyncLoading || update is AsyncLoading;
|
||||||
save is AsyncLoading || delete is AsyncLoading || update is AsyncLoading;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,37 +13,26 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|||||||
part 'profiles_overview_notifier.g.dart';
|
part 'profiles_overview_notifier.g.dart';
|
||||||
|
|
||||||
@riverpod
|
@riverpod
|
||||||
class ProfilesOverviewSortNotifier extends _$ProfilesOverviewSortNotifier
|
class ProfilesOverviewSortNotifier extends _$ProfilesOverviewSortNotifier with AppLogger {
|
||||||
with AppLogger {
|
|
||||||
@override
|
@override
|
||||||
({ProfilesSort by, SortMode mode}) build() {
|
({ProfilesSort by, SortMode mode}) build() {
|
||||||
return (by: ProfilesSort.lastUpdate, mode: SortMode.descending);
|
return (by: ProfilesSort.lastUpdate, mode: SortMode.descending);
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeSort(ProfilesSort sortBy) =>
|
void changeSort(ProfilesSort sortBy) => state = (by: sortBy, mode: state.mode);
|
||||||
state = (by: sortBy, mode: state.mode);
|
|
||||||
|
|
||||||
void toggleMode() => state = (
|
void toggleMode() => state = (by: state.by, mode: state.mode == SortMode.ascending ? SortMode.descending : SortMode.ascending);
|
||||||
by: state.by,
|
|
||||||
mode: state.mode == SortMode.ascending
|
|
||||||
? SortMode.descending
|
|
||||||
: SortMode.ascending
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@riverpod
|
@riverpod
|
||||||
class ProfilesOverviewNotifier extends _$ProfilesOverviewNotifier
|
class ProfilesOverviewNotifier extends _$ProfilesOverviewNotifier with AppLogger {
|
||||||
with AppLogger {
|
|
||||||
@override
|
@override
|
||||||
Stream<List<ProfileEntity>> build() {
|
Stream<List<ProfileEntity>> build() {
|
||||||
final sort = ref.watch(profilesOverviewSortNotifierProvider);
|
final sort = ref.watch(profilesOverviewSortNotifierProvider);
|
||||||
return _profilesRepo
|
return _profilesRepo.watchAll(sort: sort.by, sortMode: sort.mode).map((event) => event.getOrElse((l) => throw l));
|
||||||
.watchAll(sort: sort.by, sortMode: sort.mode)
|
|
||||||
.map((event) => event.getOrElse((l) => throw l));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileRepository get _profilesRepo =>
|
ProfileRepository get _profilesRepo => ref.read(profileRepositoryProvider).requireValue;
|
||||||
ref.read(profileRepositoryProvider).requireValue;
|
|
||||||
|
|
||||||
Future<Unit> selectActiveProfile(String id) async {
|
Future<Unit> selectActiveProfile(String id) async {
|
||||||
loggy.debug('changing active profile to: [$id]');
|
loggy.debug('changing active profile to: [$id]');
|
||||||
|
|||||||
2
libcore
2
libcore
Submodule libcore updated: 77fe588eae...d52ac5854b
@@ -20,6 +20,10 @@ dependencies:
|
|||||||
git:
|
git:
|
||||||
url: https://github.com/alex-relov/humanizer
|
url: https://github.com/alex-relov/humanizer
|
||||||
ref: up-version
|
ref: up-version
|
||||||
|
# lucy_editor: ^1.0.5
|
||||||
|
# re_highlight: ^0.0.3
|
||||||
|
# json_editor_flutter: ^1.4.2
|
||||||
|
|
||||||
slang: ^3.30.1
|
slang: ^3.30.1
|
||||||
slang_flutter: ^3.30.0
|
slang_flutter: ^3.30.0
|
||||||
fpdart: ^1.1.0
|
fpdart: ^1.1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user