Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat: better query manager

Predidita6f1cbbab91b
diff --git a/lib/pages/info/source_sheet.dart b/lib/pages/info/source_sheet.dart
index 90ed52b5..e72fd815 100644
--- a/lib/pages/info/source_sheet.dart
+++ b/lib/pages/info/source_sheet.dart
@@ -43,16 +43,15 @@ class _SourceSheetState extends State<SourceSheet>
keyword = widget.infoController.bangumiItem.nameCn == ''
? widget.infoController.bangumiItem.name
: widget.infoController.bangumiItem.nameCn;
- if (widget.infoController.pluginSearchResponseList.isEmpty) {
- queryManager = QueryManager(infoController: widget.infoController);
- queryManager?.queryAllSource(keyword);
- }
+ queryManager = QueryManager(infoController: widget.infoController);
+ queryManager?.queryAllSource(keyword);
super.initState();
}
@override
void dispose() {
queryManager?.cancel();
+ queryManager = null;
super.dispose();
}
@@ -199,43 +198,64 @@ class _SourceSheetState extends State<SourceSheet>
tabs: pluginsController.pluginList
.map(
(plugin) => Observer(
- builder: (context) => Tab(
- child: Row(
- children: [
- Text(
- plugin.name,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- fontSize: Theme.of(context)
- .textTheme
- .titleMedium!
- .fontSize,
- color: Theme.of(context)
- .colorScheme
- .onSurface),
- ),
- const SizedBox(width: 5.0),
- Container(
- width: 8.0,
- height: 8.0,
- decoration: BoxDecoration(
- color: widget.infoController
- .pluginSearchStatus[
- plugin.name] ==
- 'success'
- ? Colors.green
- : (widget.infoController
- .pluginSearchStatus[
- plugin.name] ==
- 'pending')
- ? Colors.grey
- : Colors.red,
- shape: BoxShape.circle,
+ builder: (context) {
+ bool isSuccessButEmpty = false;
+ if (widget.infoController
+ .pluginSearchStatus[plugin.name] ==
+ 'success') {
+ bool hasContent = false;
+ for (var searchResponse in widget
+ .infoController.pluginSearchResponseList) {
+ if (searchResponse.pluginName ==
+ plugin.name &&
+ searchResponse.data.isNotEmpty) {
+ hasContent = true;
+ break;
+ }
+ }
+ isSuccessButEmpty = !hasContent;
+ }
+
+ return Tab(
+ child: Row(
+ children: [
+ Text(
+ plugin.name,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ fontSize: Theme.of(context)
+ .textTheme
+ .titleMedium!
+ .fontSize,
+ color: Theme.of(context)
+ .colorScheme
+ .onSurface),
),
- ),
- ],
- ),
- ),
+ const SizedBox(width: 5.0),
+ Container(
+ width: 8.0,
+ height: 8.0,
+ decoration: BoxDecoration(
+ color: isSuccessButEmpty
+ ? Colors.orange
+ : (widget.infoController
+ .pluginSearchStatus[
+ plugin.name] ==
+ 'success'
+ ? Colors.green
+ : (widget.infoController
+ .pluginSearchStatus[
+ plugin.name] ==
+ 'pending')
+ ? Colors.grey
+ : Colors.red),
+ shape: BoxShape.circle,
+ ),
+ ),
+ ],
+ ),
+ );
+ },
),
)
.toList(),
diff --git a/lib/request/query_manager.dart b/lib/request/query_manager.dart
index 40798e3a..c99a23d3 100644
--- a/lib/request/query_manager.dart
+++ b/lib/request/query_manager.dart
@@ -12,7 +12,7 @@ class QueryManager {
final InfoController infoController;
final PluginsController pluginsController = Modular.get<PluginsController>();
- late StreamController _controller;
+ StreamController? _controller;
bool _isCancelled = false;
Future<void> querySource(String keyword, String pluginName) async {
@@ -29,7 +29,9 @@ class QueryManager {
for (Plugin plugin in pluginsController.pluginList) {
if (plugin.name == pluginName) {
plugin.queryBangumi(keyword, shouldRethrow: true).then((result) {
- if (_isCancelled) return;
+ if (_isCancelled) {
+ return;
+ }
infoController.pluginSearchStatus[plugin.name] = 'success';
if (result.data.isNotEmpty) {
@@ -37,7 +39,9 @@ class QueryManager {
}
infoController.pluginSearchResponseList.add(result);
}).catchError((error) {
- if (_isCancelled) return;
+ if (_isCancelled) {
+ return;
+ }
infoController.pluginSearchStatus[plugin.name] = 'error';
});
@@ -57,21 +61,25 @@ class QueryManager {
if (_isCancelled) return;
plugin.queryBangumi(keyword, shouldRethrow: true).then((result) {
- if (_isCancelled) return;
+ if (_isCancelled) {
+ return;
+ }
infoController.pluginSearchStatus[plugin.name] = 'success';
if (result.data.isNotEmpty) {
pluginsController.validityTracker.markSearchValid(plugin.name);
}
- _controller.add(result);
+ _controller?.add(result);
}).catchError((error) {
- if (_isCancelled) return;
+ if (_isCancelled) {
+ return;
+ }
infoController.pluginSearchStatus[plugin.name] = 'error';
});
}
- await for (var result in _controller.stream) {
+ await for (var result in _controller!.stream) {
if (_isCancelled) break;
infoController.pluginSearchResponseList.add(result);
@@ -80,6 +88,8 @@ class QueryManager {
void cancel() {
_isCancelled = true;
- _controller.close();
+ if (_controller != null && !_controller!.isClosed) {
+ _controller!.close();
+ }
}
}