2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
|
|
|
|
import 'package:fl_clash/models/models.dart';
|
|
|
|
|
import 'package:fl_clash/state.dart';
|
2025-06-07 01:48:34 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
|
|
|
|
|
part 'generated/app.g.dart';
|
|
|
|
|
|
2025-05-02 02:24:12 +08:00
|
|
|
@riverpod
|
|
|
|
|
class RealTunEnable extends _$RealTunEnable with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
bool build() {
|
|
|
|
|
return globalState.appState.realTunEnable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(realTunEnable: value);
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@riverpod
|
|
|
|
|
class Logs extends _$Logs with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
FixedList<Log> build() {
|
|
|
|
|
return globalState.appState.logs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void addLog(Log value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
this.value = state.copyWith()..add(value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(logs: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Requests extends _$Requests with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
2025-06-07 01:48:34 +08:00
|
|
|
FixedList<TrackerInfo> build() {
|
2025-02-09 18:39:38 +08:00
|
|
|
return globalState.appState.requests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(requests: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void addRequest(TrackerInfo value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
this.value = state.copyWith()..add(value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
2025-07-31 17:09:18 +08:00
|
|
|
class Providers extends _$Providers with AnyNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<ExternalProvider> get value => globalState.appState.providers;
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@override
|
|
|
|
|
List<ExternalProvider> build() {
|
|
|
|
|
return globalState.appState.providers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(providers: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setProvider(ExternalProvider? provider) {
|
2025-07-31 17:09:18 +08:00
|
|
|
if (!ref.mounted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
if (provider == null) return;
|
2025-07-31 17:09:18 +08:00
|
|
|
final index = value.indexWhere((item) => item.name == provider.name);
|
2025-02-09 18:39:38 +08:00
|
|
|
if (index == -1) return;
|
2025-07-31 17:09:18 +08:00
|
|
|
final newState = List<ExternalProvider>.from(value)..[index] = provider;
|
|
|
|
|
value = newState;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Packages extends _$Packages with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<Package> build() {
|
|
|
|
|
return globalState.appState.packages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(packages: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
2025-06-07 01:48:34 +08:00
|
|
|
class SystemBrightness extends _$SystemBrightness
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
2025-02-09 18:39:38 +08:00
|
|
|
@override
|
2025-06-07 01:48:34 +08:00
|
|
|
Brightness build() {
|
2025-02-09 18:39:38 +08:00
|
|
|
return globalState.appState.brightness;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(brightness: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setState(Brightness value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
this.value = value;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Traffics extends _$Traffics with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
FixedList<Traffic> build() {
|
|
|
|
|
return globalState.appState.traffics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(traffics: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void addTraffic(Traffic value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
this.value = state.copyWith()..add(value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void clear() {
|
2025-07-31 17:09:18 +08:00
|
|
|
value = state.copyWith()..clear();
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class TotalTraffic extends _$TotalTraffic with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
Traffic build() {
|
|
|
|
|
return globalState.appState.totalTraffic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(totalTraffic: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class LocalIp extends _$LocalIp with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
String? build() {
|
|
|
|
|
return globalState.appState.localIp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(localIp: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class RunTime extends _$RunTime with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
int? build() {
|
|
|
|
|
return globalState.appState.runTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(runTime: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
2025-03-12 17:15:31 +08:00
|
|
|
class ViewSize extends _$ViewSize with AutoDisposeNotifierMixin {
|
2025-02-09 18:39:38 +08:00
|
|
|
@override
|
2025-03-12 17:15:31 +08:00
|
|
|
Size build() {
|
|
|
|
|
return globalState.appState.viewSize;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(viewSize: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
2025-07-31 17:09:18 +08:00
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
@riverpod
|
|
|
|
|
class SideWidth extends _$SideWidth with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
double build() {
|
|
|
|
|
return globalState.appState.sideWidth;
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(sideWidth: value);
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
@riverpod
|
|
|
|
|
double viewWidth(Ref ref) {
|
|
|
|
|
return ref.watch(viewSizeProvider).width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
ViewMode viewMode(Ref ref) {
|
2025-04-09 16:46:14 +08:00
|
|
|
return utils.getViewMode(ref.watch(viewWidthProvider));
|
2025-03-12 17:15:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
bool isMobileView(Ref ref) {
|
|
|
|
|
return ref.watch(viewModeProvider) == ViewMode.mobile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
double viewHeight(Ref ref) {
|
|
|
|
|
return ref.watch(viewSizeProvider).height;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@riverpod
|
|
|
|
|
class Init extends _$Init with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
bool build() {
|
|
|
|
|
return globalState.appState.isInit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(isInit: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class CurrentPageLabel extends _$CurrentPageLabel
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
PageLabel build() {
|
|
|
|
|
return globalState.appState.pageLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(pageLabel: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class SortNum extends _$SortNum with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
int build() {
|
|
|
|
|
return globalState.appState.sortNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(sortNum: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
int add() => state++;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class CheckIpNum extends _$CheckIpNum with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
int build() {
|
|
|
|
|
return globalState.appState.checkIpNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(checkIpNum: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
int add() => state++;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-02 02:24:12 +08:00
|
|
|
@riverpod
|
|
|
|
|
class BackBlock extends _$BackBlock with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
bool build() {
|
|
|
|
|
return globalState.appState.backBlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(backBlock: value);
|
2025-05-02 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
@riverpod
|
|
|
|
|
class Loading extends _$Loading with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
bool build() {
|
|
|
|
|
return globalState.appState.loading;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(loading: value);
|
2025-06-07 01:48:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@riverpod
|
|
|
|
|
class Version extends _$Version with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
int build() {
|
|
|
|
|
return globalState.appState.version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(version: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Groups extends _$Groups with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<Group> build() {
|
|
|
|
|
return globalState.appState.groups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(groups: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class DelayDataSource extends _$DelayDataSource with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
DelayMap build() {
|
|
|
|
|
return globalState.appState.delayMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.appState = globalState.appState.copyWith(delayMap: value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setDelay(Delay delay) {
|
2025-02-09 18:39:38 +08:00
|
|
|
if (state[delay.url]?[delay.name] != delay.value) {
|
|
|
|
|
final DelayMap newDelayMap = Map.from(state);
|
|
|
|
|
if (newDelayMap[delay.url] == null) {
|
|
|
|
|
newDelayMap[delay.url] = {};
|
|
|
|
|
}
|
|
|
|
|
newDelayMap[delay.url]![delay.name] = delay.value;
|
2025-07-31 17:09:18 +08:00
|
|
|
value = newDelayMap;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-09 16:46:14 +08:00
|
|
|
|
|
|
|
|
@riverpod
|
2025-06-07 01:48:34 +08:00
|
|
|
class SystemUiOverlayStyleState extends _$SystemUiOverlayStyleState
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
2025-04-09 16:46:14 +08:00
|
|
|
@override
|
2025-06-07 01:48:34 +08:00
|
|
|
SystemUiOverlayStyle build() {
|
|
|
|
|
return globalState.appState.systemUiOverlayStyle;
|
2025-04-09 16:46:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
2025-06-07 01:48:34 +08:00
|
|
|
systemUiOverlayStyle: value,
|
2025-04-09 16:46:14 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-31 17:09:18 +08:00
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class ProfileOverrideState extends _$ProfileOverrideState
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
ProfileOverrideModel? build() {
|
|
|
|
|
return globalState.appState.profileOverrideModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
profileOverrideModel: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateState(
|
|
|
|
|
ProfileOverrideModel? Function(ProfileOverrideModel? state) builder,
|
|
|
|
|
) {
|
|
|
|
|
final value = builder(state);
|
|
|
|
|
if (value == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Riverpod(name: 'coreStatusProvider')
|
|
|
|
|
class _CoreStatus extends _$CoreStatus with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
CoreStatus build() {
|
|
|
|
|
return globalState.appState.coreStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(coreStatus: value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class QueryMap extends _$QueryMap with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
Map<QueryTag, String> build() => globalState.appState.queryMap;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(queryMap: value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateQuery(QueryTag tag, String value) {
|
|
|
|
|
this.value = Map.from(globalState.appState.queryMap)..[tag] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|