Skip to content

Commit

Permalink
update flutter and make connection more smooth
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 14, 2024
1 parent 26b8695 commit 0e0b8db
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ prepare:
@echo make macos-prepare
@echo make ios-prepare

windows-prepare: get-geo-assets get gen translate windows-libs
windows-prepare: get gen translate windows-libs

ios-prepare: get-geo-assets get gen translate ios-libs
macos-prepare: get-geo-assets get gen translate macos-libs
Expand Down
22 changes: 11 additions & 11 deletions lib/core/notification/in_app_notification_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ enum NotificationType {
}

class InAppNotificationController with AppLogger {
void showToast(
ToastificationItem showToast(
BuildContext context,
String message, {
NotificationType type = NotificationType.info,
Duration duration = const Duration(seconds: 3),
}) {
toastification.show(
return toastification.show(
context: context,
title: Text(message),
type: type._toastificationType,
Expand All @@ -43,40 +43,40 @@ class InAppNotificationController with AppLogger {
);
}

void showErrorToast(String message) {
ToastificationItem? showErrorToast(String message) {
final context = RootScaffold.stateKey.currentContext;
if (context == null) {
loggy.warning("context is null");
return;
return null;
}
showToast(
return showToast(
context,
message,
type: NotificationType.error,
duration: const Duration(seconds: 5),
);
}

void showSuccessToast(String message) {
ToastificationItem? showSuccessToast(String message) {
final context = RootScaffold.stateKey.currentContext;
if (context == null) {
loggy.warning("context is null");
return;
return null;
}
showToast(
return showToast(
context,
message,
type: NotificationType.success,
);
}

void showInfoToast(String message) {
ToastificationItem? showInfoToast(String message, {Duration duration = const Duration(seconds: 3)}) {
final context = RootScaffold.stateKey.currentContext;
if (context == null) {
loggy.warning("context is null");
return;
return null;
}
showToast(context, message);
return showToast(context, message, duration: duration);
}

Future<void> showErrorDialog(PresentableError error) async {
Expand Down
60 changes: 31 additions & 29 deletions lib/features/profile/add/add_profile_modal.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:combine/combine.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -161,9 +162,7 @@ class AddProfileModal extends HookConsumerWidget {
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
Future.microtask(() async {
addProfileModal(context, ref);
});
await addProfileModal(context, ref);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -239,41 +238,44 @@ class AddProfileModal extends HookConsumerWidget {
);
}

void addProfileModal(BuildContext context, WidgetRef ref) async {
Future<void> addProfileModal(BuildContext context, WidgetRef ref) async {
final _prefs = ref.read(sharedPreferencesProvider).requireValue;
final _warp = ref.read(warpOptionNotifierProvider.notifier);
final _profile = ref.read(addProfileProvider.notifier);
final consent = _prefs.getBool(warpConsentGiven) ?? false;
final consent = false && (_prefs.getBool(warpConsentGiven) ?? false);
context.pop();
Future.microtask(() async {
final t = ref.read(translationsProvider);
final notification = ref.read(inAppNotificationControllerProvider);

if (!consent) {
final agreed = await showDialog<bool>(
context: context,
builder: (context) => const WarpLicenseAgreementModal(),
);
final t = ref.read(translationsProvider);
final notification = ref.read(inAppNotificationControllerProvider);

if (agreed ?? false) {
await _prefs.setBool(warpConsentGiven, true);
notification.showInfoToast(t.profile.add.addingWarpMsg);
await _warp.generateWarpConfig();
} else {
return null;
}
if (!consent) {
final agreed = await showDialog<bool>(
context: context,
builder: (context) => const WarpLicenseAgreementModal(),
);

if (agreed ?? false) {
await _prefs.setBool(warpConsentGiven, true);
final toast = notification.showInfoToast(t.profile.add.addingWarpMsg, duration: const Duration(milliseconds: 100));
toast?.pause();
await _warp.generateWarpConfig();
toast?.start();
} else {
return;
}
}

final accountId = _prefs.getString("warp2-account-id");
final accessToken = _prefs.getString("warp2-access-token");
final hasWarp2Config = accountId != null && accessToken != null;
final accountId = _prefs.getString("warp2-account-id");
final accessToken = _prefs.getString("warp2-access-token");
final hasWarp2Config = accountId != null && accessToken != null;

if (!hasWarp2Config) {
notification.showInfoToast(t.profile.add.addingWarpMsg);
await _warp.generateWarp2Config();
}
await _profile.add("#profile-title: Hiddify WARP\nwarp://p1@auto#National&&detour=warp://p2@auto#WoW"); //
});
if (!hasWarp2Config || true) {
final toast = notification.showInfoToast(t.profile.add.addingWarpMsg, duration: const Duration(milliseconds: 100));
toast?.pause();
await _warp.generateWarp2Config();
toast?.start();
}
await _profile.add("#profile-title: Hiddify WARP\nwarp://p1@auto#National&&detour=warp://p2@auto#WoW"); //
}
}

Expand Down
46 changes: 23 additions & 23 deletions lib/singbox/service/ffi_singbox_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate';

import 'package:combine/combine.dart';
import 'package:ffi/ffi.dart';
import 'package:fpdart/fpdart.dart';
import 'package:hiddify/core/model/directories.dart';
Expand Down Expand Up @@ -65,8 +65,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
) {
final port = _statusReceiver.sendPort.nativePort;
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
_box.setupOnce(NativeApi.initializeApiDLData);
final err = _box
.setup(
Expand Down Expand Up @@ -94,8 +94,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
bool debug,
) {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final err = _box
.parse(
path.toNativeUtf8().cast(),
Expand All @@ -116,8 +116,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
@override
TaskEither<String, Unit> changeOptions(SingboxConfigOption options) {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final json = jsonEncode(options.toJson());
final err = _box.changeConfigOptions(json.toNativeUtf8().cast()).cast<Utf8>().toDartString();
if (err.isNotEmpty) {
Expand All @@ -134,8 +134,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
String path,
) {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final response = _box
.generateConfig(
path.toNativeUtf8().cast(),
Expand All @@ -159,8 +159,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
) {
loggy.debug("starting, memory limit: [${!disableMemoryLimit}]");
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final err = _box
.start(
configPath.toNativeUtf8().cast(),
Expand All @@ -180,8 +180,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
@override
TaskEither<String, Unit> stop() {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final err = _box.stop().cast<Utf8>().toDartString();
if (err.isNotEmpty) {
return left(err);
Expand All @@ -200,8 +200,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
) {
loggy.debug("restarting, memory limit: [${!disableMemoryLimit}]");
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final err = _box
.restart(
configPath.toNativeUtf8().cast(),
Expand Down Expand Up @@ -360,8 +360,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
@override
TaskEither<String, Unit> selectOutbound(String groupTag, String outboundTag) {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final err = _box
.selectOutbound(
groupTag.toNativeUtf8().cast(),
Expand All @@ -381,8 +381,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
@override
TaskEither<String, Unit> urlTest(String groupTag) {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final err = _box.urlTest(groupTag.toNativeUtf8().cast()).cast<Utf8>().toDartString();
if (err.isNotEmpty) {
return left(err);
Expand Down Expand Up @@ -410,8 +410,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
@override
TaskEither<String, Unit> clearLogs() {
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
_logBuffer.clear();
return right(unit);
},
Expand Down Expand Up @@ -444,8 +444,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
}) {
loggy.debug("generating warp config");
return TaskEither(
() => Future.microtask(
() async {
() => CombineWorker().execute(
() {
final response = _box
.generateWarpConfig(
licenseKey.toNativeUtf8().cast(),
Expand Down
Loading

0 comments on commit 0e0b8db

Please sign in to comment.