Add android per-app proxy

This commit is contained in:
problematicconsumer
2023-09-13 23:19:16 +03:30
parent f1b0f8ee4b
commit ea6f8b5fad
16 changed files with 587 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/environment.dart';
import 'package:hiddify/domain/singbox/singbox.dart';
import 'package:hiddify/utils/pref_notifier.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
@@ -37,6 +38,54 @@ class DebugModeNotifier extends _$DebugModeNotifier {
}
}
@Riverpod(keepAlive: true)
class PerAppProxyModeNotifier extends _$PerAppProxyModeNotifier {
late final _pref = Pref(
ref.watch(sharedPreferencesProvider),
"per_app_proxy_mode",
PerAppProxyMode.off,
mapFrom: PerAppProxyMode.values.byName,
mapTo: (value) => value.name,
);
@override
PerAppProxyMode build() => _pref.getValue();
Future<void> update(PerAppProxyMode value) {
state = value;
return _pref.update(value);
}
}
@Riverpod(keepAlive: true)
class PerAppProxyList extends _$PerAppProxyList {
late final _include = Pref(
ref.watch(sharedPreferencesProvider),
"per_app_proxy_include_list",
<String>[],
);
late final _exclude = Pref(
ref.watch(sharedPreferencesProvider),
"per_app_proxy_exclude_list",
<String>[],
);
@override
List<String> build() =>
ref.watch(perAppProxyModeNotifierProvider) == PerAppProxyMode.include
? _include.getValue()
: _exclude.getValue();
Future<void> update(List<String> value) {
state = value;
if (ref.read(perAppProxyModeNotifierProvider) == PerAppProxyMode.include) {
return _include.update(value);
}
return _exclude.update(value);
}
}
@riverpod
class MarkNewProfileActive extends _$MarkNewProfileActive {
late final _pref = Pref(

View File

@@ -22,6 +22,7 @@ part 'mobile_routes.g.dart';
path: SettingsRoute.path,
routes: [
TypedGoRoute<ConfigOptionsRoute>(path: ConfigOptionsRoute.path),
TypedGoRoute<PerAppProxyRoute>(path: PerAppProxyRoute.path),
],
),
TypedGoRoute<AboutRoute>(path: AboutRoute.path),
@@ -84,6 +85,21 @@ class ConfigOptionsRoute extends GoRouteData {
}
}
class PerAppProxyRoute extends GoRouteData {
const PerAppProxyRoute();
static const path = 'per-app-proxy';
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const MaterialPage(
fullscreenDialog: true,
child: PerAppProxyPage(),
);
}
}
class AboutRoute extends GoRouteData {
const AboutRoute();
static const path = 'about';