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-03-12 17:15:31 +08:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
realTunEnable: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-02-09 18:39:38 +08:00
|
|
|
state = state.copyWith()..add(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
logs: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
requests: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void addRequest(TrackerInfo value) {
|
2025-02-09 18:39:38 +08:00
|
|
|
state = state.copyWith()..add(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Providers extends _$Providers with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<ExternalProvider> build() {
|
|
|
|
|
return globalState.appState.providers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
providers: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setProvider(ExternalProvider? provider) {
|
2025-02-09 18:39:38 +08:00
|
|
|
if (provider == null) return;
|
|
|
|
|
final index = state.indexWhere((item) => item.name == provider.name);
|
|
|
|
|
if (index == -1) return;
|
|
|
|
|
state = List.from(state)..[index] = provider;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Packages extends _$Packages with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<Package> build() {
|
|
|
|
|
return globalState.appState.packages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
packages: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
brightness: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void setState(Brightness value) {
|
2025-02-09 18:39:38 +08:00
|
|
|
state = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Traffics extends _$Traffics with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
FixedList<Traffic> build() {
|
|
|
|
|
return globalState.appState.traffics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
traffics: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void addTraffic(Traffic value) {
|
2025-02-09 18:39:38 +08:00
|
|
|
state = state.copyWith()..add(value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-07 01:48:34 +08:00
|
|
|
void clear() {
|
2025-02-09 18:39:38 +08:00
|
|
|
state = state.copyWith()..clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class TotalTraffic extends _$TotalTraffic with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
Traffic build() {
|
|
|
|
|
return globalState.appState.totalTraffic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
totalTraffic: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class LocalIp extends _$LocalIp with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
String? build() {
|
|
|
|
|
return globalState.appState.localIp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
localIp: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
set state(String? value) {
|
|
|
|
|
super.state = value;
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
localIp: state,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class RunTime extends _$RunTime with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
int? build() {
|
|
|
|
|
return globalState.appState.runTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
runTime: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool get isStart {
|
|
|
|
|
return state != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
2025-03-12 17:15:31 +08:00
|
|
|
viewSize: value,
|
2025-02-09 18:39:38 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-09 16:46:14 +08:00
|
|
|
ViewMode get viewMode => utils.getViewMode(state.width);
|
2025-02-09 18:39:38 +08:00
|
|
|
|
|
|
|
|
bool get isMobileView => viewMode == ViewMode.mobile;
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
isInit: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class CurrentPageLabel extends _$CurrentPageLabel
|
|
|
|
|
with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
PageLabel build() {
|
|
|
|
|
return globalState.appState.pageLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
pageLabel: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class SortNum extends _$SortNum with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
int build() {
|
|
|
|
|
return globalState.appState.sortNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
sortNum: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
checkIpNum: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
backBlock: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
loading: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
version: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class Groups extends _$Groups with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
List<Group> build() {
|
|
|
|
|
return globalState.appState.groups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
groups: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
|
class DelayDataSource extends _$DelayDataSource with AutoDisposeNotifierMixin {
|
|
|
|
|
@override
|
|
|
|
|
DelayMap build() {
|
|
|
|
|
return globalState.appState.delayMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
onUpdate(value) {
|
|
|
|
|
globalState.appState = globalState.appState.copyWith(
|
|
|
|
|
delayMap: value,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
state = newDelayMap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|