Add core mode
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
// ignore_for_file: avoid_manual_providers_as_generated_provider_dependency
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/data/data_providers.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/utils/pref_notifier.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'config_options_store.g.dart';
|
||||
@@ -11,6 +13,25 @@ final _default = ConfigOptions.initial;
|
||||
final executeConfigAsIs =
|
||||
PrefNotifier.provider("execute-config-as-is", _default.executeConfigAsIs);
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class CoreModeStore extends _$CoreModeStore {
|
||||
late final _pref = Pref(
|
||||
ref.watch(sharedPreferencesProvider),
|
||||
"mode",
|
||||
PlatformUtils.isDesktop ? CoreMode.proxy : CoreMode.tun,
|
||||
mapFrom: CoreMode.values.byName,
|
||||
mapTo: (value) => value.name,
|
||||
);
|
||||
|
||||
@override
|
||||
CoreMode build() => _pref.getValue();
|
||||
|
||||
Future<void> update(CoreMode value) {
|
||||
state = value;
|
||||
return _pref.update(value);
|
||||
}
|
||||
}
|
||||
|
||||
final logLevelStore = PrefNotifier.provider(
|
||||
"log-level",
|
||||
_default.logLevel,
|
||||
@@ -104,7 +125,9 @@ List<Rule> rules(RulesRef ref) => switch (ref.watch(regionNotifierProvider)) {
|
||||
};
|
||||
|
||||
@riverpod
|
||||
ConfigOptions configOptions(ConfigOptionsRef ref) => ConfigOptions(
|
||||
ConfigOptions configOptions(ConfigOptionsRef ref) {
|
||||
final mode = ref.watch(coreModeStoreProvider);
|
||||
return ConfigOptions(
|
||||
executeConfigAsIs:
|
||||
ref.watch(debugModeNotifierProvider) && ref.watch(executeConfigAsIs),
|
||||
logLevel: ref.watch(logLevelStore),
|
||||
@@ -122,7 +145,8 @@ ConfigOptions configOptions(ConfigOptionsRef ref) => ConfigOptions(
|
||||
urlTestInterval: ref.watch(urlTestIntervalStore),
|
||||
enableClashApi: ref.watch(enableClashApiStore),
|
||||
clashApiPort: ref.watch(clashApiPortStore),
|
||||
enableTun: ref.watch(enableTunStore),
|
||||
setSystemProxy: ref.watch(setSystemProxyStore),
|
||||
enableTun: mode == CoreMode.tun || ref.watch(enableTunStore),
|
||||
setSystemProxy: mode == CoreMode.proxy || ref.watch(setSystemProxyStore),
|
||||
rules: ref.watch(rulesProvider),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/domain/singbox/box_log.dart';
|
||||
import 'package:hiddify/domain/singbox/rules.dart';
|
||||
import 'package:hiddify/utils/platform_utils.dart';
|
||||
|
||||
part 'config_options.freezed.dart';
|
||||
part 'config_options.g.dart';
|
||||
@@ -34,16 +33,13 @@ class ConfigOptions with _$ConfigOptions {
|
||||
@Default(true) bool enableClashApi,
|
||||
@Default(6756) int clashApiPort,
|
||||
@Default(false) bool enableTun,
|
||||
@Default(true) bool setSystemProxy,
|
||||
@Default(false) bool setSystemProxy,
|
||||
@Default(false) bool bypassLan,
|
||||
@Default(false) bool enableFakeDns,
|
||||
List<Rule>? rules,
|
||||
}) = _ConfigOptions;
|
||||
|
||||
static ConfigOptions initial = ConfigOptions(
|
||||
enableTun: !PlatformUtils.isDesktop,
|
||||
setSystemProxy: PlatformUtils.isDesktop,
|
||||
);
|
||||
static ConfigOptions initial = const ConfigOptions();
|
||||
|
||||
String format() {
|
||||
const encoder = JsonEncoder.withIndent(' ');
|
||||
|
||||
13
lib/domain/singbox/core_mode.dart
Normal file
13
lib/domain/singbox/core_mode.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:hiddify/core/prefs/locale_prefs.dart';
|
||||
|
||||
enum CoreMode {
|
||||
none,
|
||||
proxy,
|
||||
tun;
|
||||
|
||||
String present(TranslationsEn t) => switch (this) {
|
||||
none => t.settings.config.modes.none,
|
||||
proxy => t.settings.config.modes.proxy,
|
||||
tun => t.settings.config.modes.tun,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export 'box_log.dart';
|
||||
export 'config_options.dart';
|
||||
export 'core_mode.dart';
|
||||
export 'core_status.dart';
|
||||
export 'outbounds.dart';
|
||||
export 'proxy_type.dart';
|
||||
|
||||
Reference in New Issue
Block a user