Add reset tunnel option on ios
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:hiddify/features/settings/data/settings_data_providers.dart';
|
||||
import 'package:hiddify/singbox/service/singbox_service_provider.dart';
|
||||
import 'package:hiddify/utils/custom_loggers.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'platform_settings_notifier.g.dart';
|
||||
@@ -23,3 +25,21 @@ class IgnoreBatteryOptimizations extends _$IgnoreBatteryOptimizations {
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class ResetTunnel extends _$ResetTunnel with AppLogger {
|
||||
@override
|
||||
Future<void> build() async {}
|
||||
|
||||
Future<void> run() async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() => ref.read(singboxServiceProvider).resetTunnel().getOrElse(
|
||||
(err) {
|
||||
loggy.warning("error resetting tunnel", err);
|
||||
throw err;
|
||||
},
|
||||
).run(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:hiddify/core/preferences/general_preferences.dart';
|
||||
import 'package:hiddify/core/router/router.dart';
|
||||
import 'package:hiddify/features/common/general_pref_tiles.dart';
|
||||
import 'package:hiddify/features/per_app_proxy/model/per_app_proxy_mode.dart';
|
||||
import 'package:hiddify/features/settings/notifier/platform_settings_notifier.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
@@ -72,6 +73,14 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
await ref.read(disableMemoryLimitProvider.notifier).update(!value);
|
||||
},
|
||||
),
|
||||
if (Platform.isIOS)
|
||||
ListTile(
|
||||
title: Text(t.settings.advanced.resetTunnel),
|
||||
leading: const Icon(Icons.restart_alt),
|
||||
onTap: () async {
|
||||
await ref.read(resetTunnelProvider.notifier).run();
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(t.settings.advanced.debugMode),
|
||||
value: debug,
|
||||
|
||||
@@ -224,6 +224,13 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<String, Unit> resetTunnel() {
|
||||
throw UnimplementedError(
|
||||
"reset tunnel function unavailable on platform",
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<SingboxStatus> watchStatus() => _status;
|
||||
|
||||
|
||||
@@ -147,6 +147,24 @@ class PlatformSingboxService with InfraLogger implements SingboxService {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<String, Unit> resetTunnel() {
|
||||
return TaskEither(
|
||||
() async {
|
||||
// only available on iOS (and macOS later)
|
||||
if (!Platform.isIOS) {
|
||||
throw UnimplementedError(
|
||||
"reset tunnel function unavailable on platform",
|
||||
);
|
||||
}
|
||||
|
||||
loggy.debug("resetting tunnel");
|
||||
await _methodChannel.invokeMethod("reset");
|
||||
return right(unit);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<SingboxOutboundGroup>> watchOutbounds() {
|
||||
const channel = EventChannel("com.hiddify.app/groups");
|
||||
|
||||
@@ -52,6 +52,8 @@ abstract interface class SingboxService {
|
||||
bool disableMemoryLimit,
|
||||
);
|
||||
|
||||
TaskEither<String, Unit> resetTunnel();
|
||||
|
||||
Stream<List<SingboxOutboundGroup>> watchOutbounds();
|
||||
|
||||
TaskEither<String, Unit> selectOutbound(String groupTag, String outboundTag);
|
||||
|
||||
Reference in New Issue
Block a user