Add rules
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// ignore_for_file: avoid_manual_providers_as_generated_provider_dependency
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/domain/singbox/config_options.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/utils/pref_notifier.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
@@ -67,6 +67,32 @@ final enableTunStore = PrefNotifier.provider("enable-tun", _default.enableTun);
|
||||
final setSystemProxyStore =
|
||||
PrefNotifier.provider("set-system-proxy", _default.setSystemProxy);
|
||||
|
||||
// HACK temporary
|
||||
@riverpod
|
||||
List<Rule> rules(RulesRef ref) => switch (ref.watch(regionNotifierProvider)) {
|
||||
Region.ir => [
|
||||
const Rule(
|
||||
id: "id",
|
||||
name: "name",
|
||||
enabled: true,
|
||||
domains: "domain:.ir",
|
||||
ip: "geoip:ir",
|
||||
outbound: RuleOutbound.bypass,
|
||||
),
|
||||
],
|
||||
Region.cn => [
|
||||
const Rule(
|
||||
id: "id",
|
||||
name: "name",
|
||||
enabled: true,
|
||||
domains: "domain:.cn,geosite:cn",
|
||||
ip: "geoip:cn",
|
||||
outbound: RuleOutbound.bypass,
|
||||
),
|
||||
],
|
||||
_ => [],
|
||||
};
|
||||
|
||||
@riverpod
|
||||
ConfigOptions configOptions(ConfigOptionsRef ref) => ConfigOptions(
|
||||
executeConfigAsIs:
|
||||
@@ -88,4 +114,5 @@ ConfigOptions configOptions(ConfigOptionsRef ref) => ConfigOptions(
|
||||
clashApiPort: ref.watch(clashApiPortStore),
|
||||
enableTun: ref.watch(enableTunStore),
|
||||
setSystemProxy: ref.watch(setSystemProxyStore),
|
||||
rules: ref.watch(rulesProvider),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/domain/singbox/rules.dart';
|
||||
import 'package:hiddify/utils/platform_utils.dart';
|
||||
|
||||
part 'config_options.freezed.dart';
|
||||
@@ -19,13 +20,13 @@ class ConfigOptions with _$ConfigOptions {
|
||||
@Default(IPv6Mode.disable) IPv6Mode ipv6Mode,
|
||||
@Default("tcp://8.8.8.8") String remoteDnsAddress,
|
||||
@Default(DomainStrategy.auto) DomainStrategy remoteDnsDomainStrategy,
|
||||
@Default("8.8.8.8") String directDnsAddress,
|
||||
@Default("local") String directDnsAddress,
|
||||
@Default(DomainStrategy.auto) DomainStrategy directDnsDomainStrategy,
|
||||
@Default(2334) int mixedPort,
|
||||
@Default(6450) int localDnsPort,
|
||||
@Default(TunImplementation.mixed) TunImplementation tunImplementation,
|
||||
@Default(9000) int mtu,
|
||||
@Default("https://www.gstatic.com/generate_204") String connectionTestUrl,
|
||||
@Default("http://cp.cloudflare.com/") String connectionTestUrl,
|
||||
@IntervalConverter()
|
||||
@Default(Duration(minutes: 10))
|
||||
Duration urlTestInterval,
|
||||
@@ -33,6 +34,9 @@ class ConfigOptions with _$ConfigOptions {
|
||||
@Default(6756) int clashApiPort,
|
||||
@Default(false) bool enableTun,
|
||||
@Default(true) bool setSystemProxy,
|
||||
@Default(false) bool bypassLan,
|
||||
@Default(false) bool enableFakeDns,
|
||||
List<Rule>? rules,
|
||||
}) = _ConfigOptions;
|
||||
|
||||
static ConfigOptions initial = ConfigOptions(
|
||||
|
||||
@@ -1,5 +1,40 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/prefs/locale_prefs.dart';
|
||||
|
||||
part 'rules.freezed.dart';
|
||||
part 'rules.g.dart';
|
||||
|
||||
@freezed
|
||||
class Rule with _$Rule {
|
||||
@JsonSerializable(fieldRename: FieldRename.kebab)
|
||||
const factory Rule({
|
||||
required String id,
|
||||
required String name,
|
||||
@Default(false) bool enabled,
|
||||
String? domains,
|
||||
String? ip,
|
||||
String? port,
|
||||
String? protocol,
|
||||
@Default(RuleNetwork.tcpAndUdp) RuleNetwork network,
|
||||
@Default(RuleOutbound.proxy) RuleOutbound outbound,
|
||||
}) = _Rule;
|
||||
|
||||
factory Rule.fromJson(Map<String, dynamic> json) => _$RuleFromJson(json);
|
||||
}
|
||||
|
||||
enum RuleOutbound { proxy, bypass, block }
|
||||
|
||||
@JsonEnum(valueField: 'key')
|
||||
enum RuleNetwork {
|
||||
tcpAndUdp(""),
|
||||
tcp("tcp"),
|
||||
udp("udp");
|
||||
|
||||
const RuleNetwork(this.key);
|
||||
|
||||
final String? key;
|
||||
}
|
||||
|
||||
enum PerAppProxyMode {
|
||||
off,
|
||||
include,
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/core/router/routes/routes.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/features/common/common.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
@@ -20,6 +21,7 @@ class AdvancedSettingTiles extends HookConsumerWidget {
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
const RegionPrefTile(),
|
||||
ListTile(
|
||||
title: Text(t.settings.config.pageTitle),
|
||||
leading: const Icon(Icons.edit_document),
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:combine/combine.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/domain/connectivity/connectivity.dart';
|
||||
import 'package:hiddify/domain/singbox/config_options.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/gen/singbox_generated_bindings.dart';
|
||||
import 'package:hiddify/services/singbox/shared.dart';
|
||||
import 'package:hiddify/services/singbox/singbox_service.dart';
|
||||
|
||||
2
libcore
2
libcore
Submodule libcore updated: d410fe1c4b...0480a5d3ec
Reference in New Issue
Block a user