Skip to content

Commit

Permalink
new: add json editor and editing configs <3
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 30, 2024
1 parent 503e48a commit 531ddbc
Show file tree
Hide file tree
Showing 10 changed files with 1,523 additions and 135 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
TARGET_NAME_dmg: "Hiddify-MacOS"
TARGET_NAME_pkg: "Hiddify-MacOS-Installer"
TARGET_NAME_ipa: "Hiddify-iOS"
TARGET_NAME_ipa2: "Hiddify-iOS2"

jobs:
test:
Expand Down Expand Up @@ -91,6 +92,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3

- name: Import Apple Codesign Certificates
if: ${{ inputs.upload-artifact && startsWith(matrix.os,'macos') }}
uses: apple-actions/import-codesign-certs@v3
Expand All @@ -103,7 +105,7 @@ jobs:
run: |
mkdir -p ~/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.APPLE_DEVLOP_PROVISIONING_PROFILES_TARGZ_BASE64}}"|base64 --decode | tar xz -C ~/Library/MobileDevice/Provisioning\ Profiles

Expand Down
3 changes: 3 additions & 0 deletions lib/features/profile/data/profile_data_providers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:hiddify/core/database/database_provider.dart';
import 'package:hiddify/core/directories/directories_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_path_resolver.dart';
import 'package:hiddify/features/profile/data/profile_repository.dart';
Expand All @@ -15,6 +17,7 @@ Future<ProfileRepository> profileRepository(ProfileRepositoryRef ref) async {
profileDataSource: ref.watch(profileDataSourceProvider),
profilePathResolver: ref.watch(profilePathResolverProvider),
singbox: ref.watch(singboxServiceProvider),
configOptionRepository: ref.watch(configOptionRepositoryProvider),
httpClient: ref.watch(httpClientProvider),
);
await repo.init().getOrElse((l) => throw l).run();
Expand Down
71 changes: 50 additions & 21 deletions lib/features/profile/data/profile_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:fpdart/fpdart.dart';
import 'package:hiddify/core/database/app_database.dart';
import 'package:hiddify/core/http_client/dio_http_client.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_source.dart';
import 'package:hiddify/features/profile/data/profile_parser.dart';
Expand Down Expand Up @@ -36,7 +38,10 @@ abstract interface class ProfileRepository {
bool markAsActive = false,
CancelToken? cancelToken,
});

TaskEither<ProfileFailure, Unit> updateContent(
String profileId,
String content,
);
TaskEither<ProfileFailure, Unit> addByContent(
String content, {
required String name,
Expand Down Expand Up @@ -67,12 +72,14 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
required this.profileDataSource,
required this.profilePathResolver,
required this.singbox,
required this.configOptionRepository,
required this.httpClient,
});

final ProfileDataSource profileDataSource;
final ProfilePathResolver profilePathResolver;
final SingboxService singbox;
final ConfigOptionRepository configOptionRepository;
final DioHttpClient httpClient;

@override
Expand Down Expand Up @@ -178,33 +185,18 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
}

@override
TaskEither<ProfileFailure, Unit> addByContent(
String content, {
required String name,
bool markAsActive = false,
}) {
TaskEither<ProfileFailure, Unit> updateContent(
String profileId,
String content,
) {
return exceptionHandler(
() async {
final profileId = const Uuid().v4();
final file = profilePathResolver.file(profileId);
final tempFile = profilePathResolver.tempFile(profileId);

try {
await tempFile.writeAsString(content);
return await validateConfig(file.path, tempFile.path, false)
.andThen(
() => TaskEither(() async {
final profile = LocalProfileEntity(
id: profileId,
active: markAsActive,
name: name,
lastUpdate: DateTime.now(),
);
await profileDataSource.insert(profile.toEntry());
return right(unit);
}),
)
.run();
return await validateConfig(file.path, tempFile.path, false).run();
} finally {
if (tempFile.existsSync()) tempFile.deleteSync();
}
Expand All @@ -216,6 +208,39 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
);
}

@override
TaskEither<ProfileFailure, Unit> addByContent(
String content, {
required String name,
bool markAsActive = false,
}) {
return exceptionHandler(
() async {
final profileId = const Uuid().v4();

return await updateContent(profileId, content)
.andThen(
() => TaskEither(() async {
final profile = LocalProfileEntity(
id: profileId,
active: markAsActive,
name: name,
lastUpdate: DateTime.now(),
);
await profileDataSource.insert(profile.toEntry());

return right(unit);
}),
)
.run();
},
(error, stackTrace) {
loggy.warning("error adding profile by content", error, stackTrace);
return ProfileUnexpectedFailure(error, stackTrace);
},
);
}

@override
TaskEither<ProfileFailure, Unit> add(
RemoteProfileEntity baseProfile, {
Expand Down Expand Up @@ -252,6 +277,10 @@ class ProfileRepositoryImpl with ExceptionHandler, InfraLogger implements Profil
($) async {
final configFile = profilePathResolver.file(id);
// TODO pass options
final options = await configOptionRepository.getConfigOptions();

singbox.changeOptions(options).mapLeft(InvalidConfigOption.new).run();

return await $(
singbox.generateFullConfigByPath(configFile.path).mapLeft(ProfileFailure.unexpected),
);
Expand Down
Loading

0 comments on commit 531ddbc

Please sign in to comment.