mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-05-10 03:51:23 +08:00
feat: add listSortReverse option to ToolsLogAnalyze provider
This commit is contained in:
parent
3c061f995c
commit
cb35c400f9
@ -22,7 +22,7 @@ final routerProvider = AutoDisposeProvider<GoRouter>.internal(
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef RouterRef = AutoDisposeProviderRef<GoRouter>;
|
||||
String _$appGlobalModelHash() => r'eb06413ab3a70f26712d897cee745ee62e89e75e';
|
||||
String _$appGlobalModelHash() => r'4e372bc744903960e4e7b146dbb394ded15e2c18';
|
||||
|
||||
/// See also [AppGlobalModel].
|
||||
@ProviderFor(AppGlobalModel)
|
||||
|
@ -6,7 +6,7 @@ part of 'nav_state.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$navHash() => r'2019b3f675fbaec4be794049d900bf2dcc8d5e37';
|
||||
String _$navHash() => r'00c4da8fdd37214cda179a81ece3676add7aab53';
|
||||
|
||||
/// See also [Nav].
|
||||
@ProviderFor(Nav)
|
||||
|
@ -38,11 +38,10 @@ class LogAnalyzeLineData with _$LogAnalyzeLineData {
|
||||
|
||||
@riverpod
|
||||
class ToolsLogAnalyze extends _$ToolsLogAnalyze {
|
||||
|
||||
static const String unknownValue = "<Unknown>";
|
||||
|
||||
@override
|
||||
Future<List<LogAnalyzeLineData>> build(String gameInstallPath) async {
|
||||
Future<List<LogAnalyzeLineData>> build(String gameInstallPath, bool listSortReverse) async {
|
||||
final logFile = File("$gameInstallPath/Game.log");
|
||||
debugPrint("[ToolsLogAnalyze] logFile: ${logFile.absolute.path}");
|
||||
if (gameInstallPath.isEmpty || !(await logFile.exists())) {
|
||||
@ -175,7 +174,11 @@ class ToolsLogAnalyze extends _$ToolsLogAnalyze {
|
||||
case ChangeType.MODIFY:
|
||||
// 移除${S.current.log_analyzer_filter_statistics}
|
||||
final newList = state.value?.where((e) => e.type != "statistics").toList();
|
||||
if (listSortReverse) {
|
||||
state = AsyncData(newList?.reversed.toList() ?? []);
|
||||
} else {
|
||||
state = AsyncData(newList ?? []);
|
||||
}
|
||||
return _launchLogAnalyze(logFile, startLine: _currentLineNumber);
|
||||
case ChangeType.ADD:
|
||||
case ChangeType.REMOVE:
|
||||
@ -253,7 +256,12 @@ class ToolsLogAnalyze extends _$ToolsLogAnalyze {
|
||||
// 追加结果到 state
|
||||
final currentState = state.value;
|
||||
if (currentState != null) {
|
||||
if (listSortReverse) {
|
||||
// 反向排序
|
||||
state = AsyncData([data, ...currentState]);
|
||||
} else {
|
||||
state = AsyncData([...currentState, data]);
|
||||
}
|
||||
} else {
|
||||
state = AsyncData([data]);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ part of 'log_analyze_provider.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$toolsLogAnalyzeHash() => r'cc8aed5b4eeb6c8feb35c59ef484dc61c92a5549';
|
||||
String _$toolsLogAnalyzeHash() => r'5666c3f882e22e2192593629164bc53f8ce4aabe';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
@ -32,9 +32,11 @@ class _SystemHash {
|
||||
abstract class _$ToolsLogAnalyze
|
||||
extends BuildlessAutoDisposeAsyncNotifier<List<LogAnalyzeLineData>> {
|
||||
late final String gameInstallPath;
|
||||
late final bool listSortReverse;
|
||||
|
||||
FutureOr<List<LogAnalyzeLineData>> build(
|
||||
String gameInstallPath,
|
||||
bool listSortReverse,
|
||||
);
|
||||
}
|
||||
|
||||
@ -51,9 +53,11 @@ class ToolsLogAnalyzeFamily
|
||||
/// See also [ToolsLogAnalyze].
|
||||
ToolsLogAnalyzeProvider call(
|
||||
String gameInstallPath,
|
||||
bool listSortReverse,
|
||||
) {
|
||||
return ToolsLogAnalyzeProvider(
|
||||
gameInstallPath,
|
||||
listSortReverse,
|
||||
);
|
||||
}
|
||||
|
||||
@ -63,6 +67,7 @@ class ToolsLogAnalyzeFamily
|
||||
) {
|
||||
return call(
|
||||
provider.gameInstallPath,
|
||||
provider.listSortReverse,
|
||||
);
|
||||
}
|
||||
|
||||
@ -87,8 +92,11 @@ class ToolsLogAnalyzeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
/// See also [ToolsLogAnalyze].
|
||||
ToolsLogAnalyzeProvider(
|
||||
String gameInstallPath,
|
||||
bool listSortReverse,
|
||||
) : this._internal(
|
||||
() => ToolsLogAnalyze()..gameInstallPath = gameInstallPath,
|
||||
() => ToolsLogAnalyze()
|
||||
..gameInstallPath = gameInstallPath
|
||||
..listSortReverse = listSortReverse,
|
||||
from: toolsLogAnalyzeProvider,
|
||||
name: r'toolsLogAnalyzeProvider',
|
||||
debugGetCreateSourceHash:
|
||||
@ -99,6 +107,7 @@ class ToolsLogAnalyzeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
allTransitiveDependencies:
|
||||
ToolsLogAnalyzeFamily._allTransitiveDependencies,
|
||||
gameInstallPath: gameInstallPath,
|
||||
listSortReverse: listSortReverse,
|
||||
);
|
||||
|
||||
ToolsLogAnalyzeProvider._internal(
|
||||
@ -109,9 +118,11 @@ class ToolsLogAnalyzeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.gameInstallPath,
|
||||
required this.listSortReverse,
|
||||
}) : super.internal();
|
||||
|
||||
final String gameInstallPath;
|
||||
final bool listSortReverse;
|
||||
|
||||
@override
|
||||
FutureOr<List<LogAnalyzeLineData>> runNotifierBuild(
|
||||
@ -119,6 +130,7 @@ class ToolsLogAnalyzeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
) {
|
||||
return notifier.build(
|
||||
gameInstallPath,
|
||||
listSortReverse,
|
||||
);
|
||||
}
|
||||
|
||||
@ -127,13 +139,16 @@ class ToolsLogAnalyzeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ToolsLogAnalyzeProvider._internal(
|
||||
() => create()..gameInstallPath = gameInstallPath,
|
||||
() => create()
|
||||
..gameInstallPath = gameInstallPath
|
||||
..listSortReverse = listSortReverse,
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
gameInstallPath: gameInstallPath,
|
||||
listSortReverse: listSortReverse,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -147,13 +162,15 @@ class ToolsLogAnalyzeProvider extends AutoDisposeAsyncNotifierProviderImpl<
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ToolsLogAnalyzeProvider &&
|
||||
other.gameInstallPath == gameInstallPath;
|
||||
other.gameInstallPath == gameInstallPath &&
|
||||
other.listSortReverse == listSortReverse;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, gameInstallPath.hashCode);
|
||||
hash = _SystemHash.combine(hash, listSortReverse.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
@ -165,6 +182,9 @@ mixin ToolsLogAnalyzeRef
|
||||
on AutoDisposeAsyncNotifierProviderRef<List<LogAnalyzeLineData>> {
|
||||
/// The parameter `gameInstallPath` of this provider.
|
||||
String get gameInstallPath;
|
||||
|
||||
/// The parameter `listSortReverse` of this provider.
|
||||
bool get listSortReverse;
|
||||
}
|
||||
|
||||
class _ToolsLogAnalyzeProviderElement
|
||||
@ -175,6 +195,9 @@ class _ToolsLogAnalyzeProviderElement
|
||||
@override
|
||||
String get gameInstallPath =>
|
||||
(origin as ToolsLogAnalyzeProvider).gameInstallPath;
|
||||
@override
|
||||
bool get listSortReverse =>
|
||||
(origin as ToolsLogAnalyzeProvider).listSortReverse;
|
||||
}
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
|
@ -15,14 +15,13 @@ class ToolsLogAnalyzeDialogUI extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final selectedPath = useState<String?>(appState.gameInstallPaths.firstOrNull);
|
||||
final logResp = ref.watch(toolsLogAnalyzeProvider(selectedPath.value ?? ""));
|
||||
final listSortReverse = useState<bool>(false);
|
||||
final provider = toolsLogAnalyzeProvider(selectedPath.value ?? "", listSortReverse.value);
|
||||
final logResp = ref.watch(provider);
|
||||
final searchText = useState<String>("");
|
||||
final searchType = useState<String?>(null);
|
||||
final lastListSize = useState<int>(0);
|
||||
|
||||
final listCtrl = useScrollController();
|
||||
|
||||
_diffData(logResp, lastListSize, listCtrl);
|
||||
return ScaffoldPage(
|
||||
content: Column(
|
||||
children: [
|
||||
@ -56,7 +55,7 @@ class ToolsLogAnalyzeDialogUI extends HookConsumerWidget {
|
||||
child: const Icon(FluentIcons.refresh),
|
||||
),
|
||||
onPressed: () {
|
||||
ref.invalidate(toolsLogAnalyzeProvider(selectedPath.value ?? ""));
|
||||
ref.invalidate(provider);
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -81,6 +80,7 @@ class ToolsLogAnalyzeDialogUI extends HookConsumerWidget {
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(width: 6),
|
||||
// 筛选 ComboBox
|
||||
ComboBox<String>(
|
||||
@ -97,6 +97,18 @@ class ToolsLogAnalyzeDialogUI extends HookConsumerWidget {
|
||||
searchType.value = value;
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
// 倒序 Icon
|
||||
Button(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 6),
|
||||
child: Transform.rotate(
|
||||
angle: listSortReverse.value ? 3.14 : 0, child: const Icon(FluentIcons.sort_lines)),
|
||||
),
|
||||
onPressed: () {
|
||||
listSortReverse.value = !listSortReverse.value;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -226,32 +238,4 @@ class ToolsLogAnalyzeDialogUI extends HookConsumerWidget {
|
||||
return Colors.white.withValues(alpha: .06);
|
||||
}
|
||||
}
|
||||
|
||||
void _diffData(
|
||||
AsyncValue<List<LogAnalyzeLineData>> logResp, ValueNotifier<int> lastListSize, ScrollController listCtrl) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (lastListSize.value == 0) {
|
||||
lastListSize.value = logResp.value?.length ?? 0;
|
||||
} else {
|
||||
// 判断当前内容是否大于一页
|
||||
if (listCtrl.position.maxScrollExtent > listCtrl.position.viewportDimension) {
|
||||
// 判断当前列表是否在底部
|
||||
if (listCtrl.position.pixels >= listCtrl.position.maxScrollExtent) {
|
||||
// 如果在底部,判断数据是否有变化
|
||||
if ((logResp.value?.length ?? 0) > lastListSize.value) {
|
||||
Future.delayed(Duration(milliseconds: 100)).then((_) {
|
||||
listCtrl.jumpTo(listCtrl.position.maxScrollExtent);
|
||||
});
|
||||
lastListSize.value = logResp.value?.length ?? 0;
|
||||
} else {
|
||||
// 回顶部
|
||||
if (listCtrl.position.pixels > 0) {
|
||||
listCtrl.jumpTo(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user