d780cb863d
Changelog: The elevated Core only answers its owner
187 lines
5.5 KiB
Dart
187 lines
5.5 KiB
Dart
import 'package:fl_clash/common/common.dart';
|
|
import 'package:fl_clash/models/models.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
part 'generated/config.g.dart';
|
|
|
|
@riverpod
|
|
class AppSetting extends _$AppSetting with AutoDisposeNotifierMixin {
|
|
@override
|
|
AppSettingProps build() {
|
|
return const AppSettingProps();
|
|
}
|
|
}
|
|
|
|
@Riverpod(keepAlive: true)
|
|
class WindowSetting extends _$WindowSetting with AutoDisposeNotifierMixin {
|
|
@override
|
|
WindowProps build() {
|
|
return const WindowProps();
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class VpnSetting extends _$VpnSetting with AutoDisposeNotifierMixin {
|
|
@override
|
|
VpnProps build() {
|
|
return const VpnProps();
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class NetworkSetting extends _$NetworkSetting with AutoDisposeNotifierMixin {
|
|
@override
|
|
NetworkProps build() {
|
|
return const NetworkProps();
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class ThemeSetting extends _$ThemeSetting with AutoDisposeNotifierMixin {
|
|
@override
|
|
ThemeProps build() {
|
|
return const ThemeProps();
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class CurrentProfileId extends _$CurrentProfileId
|
|
with AutoDisposeNotifierMixin {
|
|
@override
|
|
int? build() {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class DavSetting extends _$DavSetting with AutoDisposeNotifierMixin {
|
|
@override
|
|
DAVProps? build() {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class OverrideDns extends _$OverrideDns with AutoDisposeNotifierMixin {
|
|
@override
|
|
bool build() {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class OverrideNtp extends _$OverrideNtp with AutoDisposeNotifierMixin {
|
|
@override
|
|
bool build() {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class HotKeyActions extends _$HotKeyActions with AutoDisposeNotifierMixin {
|
|
@override
|
|
List<HotKeyAction> build() {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class ProxiesStyleSetting extends _$ProxiesStyleSetting
|
|
with AutoDisposeNotifierMixin {
|
|
@override
|
|
ProxiesStyleProps build() {
|
|
return const ProxiesStyleProps();
|
|
}
|
|
}
|
|
|
|
@Riverpod(name: 'patchClashConfigProvider')
|
|
class _PatchClashConfig extends _$PatchClashConfig
|
|
with AutoDisposeNotifierMixin {
|
|
@override
|
|
PatchClashConfig build() {
|
|
return const PatchClashConfig();
|
|
}
|
|
}
|
|
|
|
@riverpod
|
|
class ExcludeSSIDs extends _$ExcludeSSIDs with AutoDisposeNotifierMixin {
|
|
@override
|
|
List<String> build() {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
@Riverpod(name: 'configProvider')
|
|
Config _config(Ref ref) {
|
|
final appSettingProps = ref.watch(appSettingProvider);
|
|
final windowProps = ref.watch(windowSettingProvider);
|
|
final vpnProps = ref.watch(vpnSettingProvider);
|
|
final networkProps = ref.watch(networkSettingProvider);
|
|
final themeProps = ref.watch(themeSettingProvider);
|
|
final currentProfileId = ref.watch(currentProfileIdProvider);
|
|
final davProps = ref.watch(davSettingProvider);
|
|
final overrideDns = ref.watch(overrideDnsProvider);
|
|
final overrideNtp = ref.watch(overrideNtpProvider);
|
|
final hotKeyActions = ref.watch(hotKeyActionsProvider);
|
|
final proxiesStyleProps = ref.watch(proxiesStyleSettingProvider);
|
|
final patchClashConfig = ref.watch(patchClashConfigProvider);
|
|
final excludeSSIDs = ref.watch(excludeSSIDsProvider);
|
|
return Config(
|
|
appSettingProps: appSettingProps,
|
|
windowProps: windowProps,
|
|
vpnProps: vpnProps,
|
|
networkProps: networkProps,
|
|
themeProps: themeProps,
|
|
currentProfileId: currentProfileId,
|
|
davProps: davProps,
|
|
overrideDns: overrideDns,
|
|
overrideNtp: overrideNtp,
|
|
hotKeyActions: hotKeyActions,
|
|
proxiesStyleProps: proxiesStyleProps,
|
|
patchClashConfig: patchClashConfig,
|
|
excludeSSIDs: excludeSSIDs,
|
|
);
|
|
}
|
|
|
|
void writeConfig(Ref ref, Config config) {
|
|
ref.read(appSettingProvider.notifier).value = config.appSettingProps;
|
|
ref.read(windowSettingProvider.notifier).value = config.windowProps;
|
|
ref.read(vpnSettingProvider.notifier).value = config.vpnProps;
|
|
ref.read(networkSettingProvider.notifier).value = config.networkProps;
|
|
ref.read(themeSettingProvider.notifier).value = config.themeProps;
|
|
ref.read(currentProfileIdProvider.notifier).value = config.currentProfileId;
|
|
ref.read(davSettingProvider.notifier).value = config.davProps;
|
|
ref.read(overrideDnsProvider.notifier).value = config.overrideDns;
|
|
ref.read(overrideNtpProvider.notifier).value = config.overrideNtp;
|
|
ref.read(hotKeyActionsProvider.notifier).value = config.hotKeyActions;
|
|
ref.read(proxiesStyleSettingProvider.notifier).value =
|
|
config.proxiesStyleProps;
|
|
ref.read(patchClashConfigProvider.notifier).value = config.patchClashConfig
|
|
.ensureControllerSecret();
|
|
ref.read(excludeSSIDsProvider.notifier).value = config.excludeSSIDs;
|
|
}
|
|
|
|
List<Override> buildConfigOverrides(Config config) {
|
|
return [
|
|
appSettingProvider.overrideWithBuild((_, _) => config.appSettingProps),
|
|
windowSettingProvider.overrideWithBuild((_, _) => config.windowProps),
|
|
vpnSettingProvider.overrideWithBuild((_, _) => config.vpnProps),
|
|
networkSettingProvider.overrideWithBuild((_, _) => config.networkProps),
|
|
themeSettingProvider.overrideWithBuild((_, _) => config.themeProps),
|
|
currentProfileIdProvider.overrideWithBuild(
|
|
(_, _) => config.currentProfileId,
|
|
),
|
|
davSettingProvider.overrideWithBuild((_, _) => config.davProps),
|
|
overrideDnsProvider.overrideWithBuild((_, _) => config.overrideDns),
|
|
overrideNtpProvider.overrideWithBuild((_, _) => config.overrideNtp),
|
|
hotKeyActionsProvider.overrideWithBuild((_, _) => config.hotKeyActions),
|
|
proxiesStyleSettingProvider.overrideWithBuild(
|
|
(_, _) => config.proxiesStyleProps,
|
|
),
|
|
patchClashConfigProvider.overrideWithBuild(
|
|
(_, _) => config.patchClashConfig,
|
|
),
|
|
excludeSSIDsProvider.overrideWithBuild((_, _) => config.excludeSSIDs),
|
|
];
|
|
}
|