2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
|
|
|
import 'package:fl_clash/models/models.dart';
|
|
|
|
|
import 'package:fl_clash/state.dart';
|
|
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
|
|
|
|
|
part 'generated/config.g.dart';
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class AppSetting extends _$AppSetting with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
AppSettingProps build() {
|
|
|
|
|
return globalState.config.appSetting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(appSetting: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(AppSettingProps Function(AppSettingProps state) builder) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = builder(state);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class WindowSetting extends _$WindowSetting with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
WindowProps build() {
|
|
|
|
|
return globalState.config.windowProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(windowProps: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(WindowProps Function(WindowProps state) builder) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = builder(state);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class VpnSetting extends _$VpnSetting with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
VpnProps build() {
|
|
|
|
|
return globalState.config.vpnProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(vpnProps: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class NetworkSetting extends _$NetworkSetting with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
NetworkProps build() {
|
|
|
|
|
return globalState.config.networkProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(networkProps: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(NetworkProps Function(NetworkProps state) builder) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = builder(state);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class ThemeSetting extends _$ThemeSetting with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
ThemeProps build() {
|
|
|
|
|
return globalState.config.themeProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(themeProps: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(ThemeProps Function(ThemeProps state) builder) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = builder(state);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Profiles extends _$Profiles with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<Profile> build() {
|
|
|
|
|
return globalState.config.profiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(profiles: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String? _getLabel(String? label, String id) {
|
|
|
|
|
final realLabel = label ?? id;
|
2025-07-31 17:09:18 +08:00
|
|
|
final hasDup =
|
|
|
|
|
state.indexWhere(
|
|
|
|
|
(element) => element.label == realLabel && element.id != id,
|
|
|
|
|
) !=
|
2025-02-09 18:39:38 +08:00
|
|
|
-1;
|
|
|
|
|
if (hasDup) {
|
2025-04-09 16:46:14 +08:00
|
|
|
return _getLabel(utils.getOverwriteLabel(realLabel), id);
|
2025-02-09 18:39:38 +08:00
|
|
|
} else {
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setProfile(Profile profile) {
|
2025-02-09 18:39:38 +08:00
|
|
|
final List<Profile> profilesTemp = List.from(state);
|
2025-07-31 17:09:18 +08:00
|
|
|
final index = profilesTemp.indexWhere(
|
|
|
|
|
(element) => element.id == profile.id,
|
|
|
|
|
);
|
2025-02-09 18:39:38 +08:00
|
|
|
final updateProfile = profile.copyWith(
|
|
|
|
|
label: _getLabel(profile.label, profile.id),
|
|
|
|
|
);
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
profilesTemp.add(updateProfile);
|
|
|
|
|
} else {
|
|
|
|
|
profilesTemp[index] = updateProfile;
|
|
|
|
|
}
|
2025-07-31 17:09:18 +08:00
|
|
|
value = profilesTemp;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateProfile(
|
2025-07-31 17:09:18 +08:00
|
|
|
String profileId,
|
|
|
|
|
Profile Function(Profile profile) builder,
|
|
|
|
|
) {
|
2025-03-12 17:15:31 +08:00
|
|
|
final List<Profile> profilesTemp = List.from(state);
|
|
|
|
|
final index = profilesTemp.indexWhere((element) => element.id == profileId);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
profilesTemp[index] = builder(profilesTemp[index]);
|
|
|
|
|
}
|
2025-07-31 17:09:18 +08:00
|
|
|
value = profilesTemp;
|
2025-03-12 17:15:31 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void deleteProfileById(String id) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = state.where((element) => element.id != id).toList();
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class CurrentProfileId extends _$CurrentProfileId
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
String? build() {
|
|
|
|
|
return globalState.config.currentProfileId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(currentProfileId: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class AppDAVSetting extends _$AppDAVSetting with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
DAV? build() {
|
|
|
|
|
return globalState.config.dav;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(dav: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(DAV? Function(DAV? state) builder) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = builder(state);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class OverrideDns extends _$OverrideDns with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
bool build() {
|
|
|
|
|
return globalState.config.overrideDns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(overrideDns: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class HotKeyActions extends _$HotKeyActions with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<HotKeyAction> build() {
|
|
|
|
|
return globalState.config.hotKeyActions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(hotKeyActions: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class ProxiesStyleSetting extends _$ProxiesStyleSetting
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
ProxiesStyle build() {
|
|
|
|
|
return globalState.config.proxiesStyle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(proxiesStyle: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(ProxiesStyle Function(ProxiesStyle state) builder) {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = builder(state);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-02 02:24:12 +08:00
|
|
|
@riverpod
|
2025-10-14 15:13:52 +08:00
|
|
|
class Scripts extends _$Scripts with AutoDisposeNotifierMixin {
|
2025-05-02 02:24:12 +08:00
|
|
|
@override
|
2025-10-14 15:13:52 +08:00
|
|
|
List<Script> build() {
|
|
|
|
|
return globalState.config.scripts;
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-10-14 15:13:52 +08:00
|
|
|
globalState.config = globalState.config.copyWith(scripts: value);
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setScript(Script script) {
|
2025-10-14 15:13:52 +08:00
|
|
|
final list = List<Script>.from(state);
|
2025-05-02 02:24:12 +08:00
|
|
|
final index = list.indexWhere((item) => item.id == script.id);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
list[index] = script;
|
|
|
|
|
} else {
|
|
|
|
|
list.add(script);
|
|
|
|
|
}
|
2025-10-14 15:13:52 +08:00
|
|
|
value = list;
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void del(String id) {
|
2025-10-14 15:13:52 +08:00
|
|
|
final list = List<Script>.from(state);
|
|
|
|
|
final index = list.indexWhere((item) => item.id == id);
|
2025-05-02 02:24:12 +08:00
|
|
|
if (index != -1) {
|
|
|
|
|
list.removeAt(index);
|
|
|
|
|
}
|
2025-10-14 15:13:52 +08:00
|
|
|
state = list;
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
bool isExits(String label) {
|
2025-10-14 15:13:52 +08:00
|
|
|
return state.indexWhere((item) => item.label == label) != -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Rules extends _$Rules with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<Rule> build() {
|
|
|
|
|
return globalState.config.rules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.config = globalState.config.copyWith(rules: value);
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@riverpod
|
|
|
|
|
class PatchClashConfig extends _$PatchClashConfig
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
ClashConfig build() {
|
|
|
|
|
return globalState.config.patchClashConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void updateState(ClashConfig? Function(ClashConfig state) builder) {
|
2025-02-09 18:39:38 +08:00
|
|
|
final newState = builder(state);
|
|
|
|
|
if (newState == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-07-31 17:09:18 +08:00
|
|
|
value = newState;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.config = globalState.config.copyWith(patchClashConfig: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|