Skip to content

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

better plugin store

Predidite9100fad0989
diff --git a/lib/pages/plugin_editor/plugin_shop_page.dart b/lib/pages/plugin_editor/plugin_shop_page.dart
index 0064b8d5..a65d1f2f 100644
--- a/lib/pages/plugin_editor/plugin_shop_page.dart
+++ b/lib/pages/plugin_editor/plugin_shop_page.dart
@@ -22,6 +22,8 @@ class PluginShopPage extends StatefulWidget {
class _PluginShopPageState extends State<PluginShopPage> {
dynamic navigationBarState;
Box setting = GStorage.setting;
+ bool timeout = false;
+ bool loading = false;
late bool enableGitProxy;
final PluginsController pluginsController = Modular.get<PluginsController>();
@@ -43,6 +45,167 @@ class _PluginShopPageState extends State<PluginShopPage> {
}
}
+ void _handleRefresh() async {
+ if (!loading) {
+ setState(() {
+ loading = true;
+ timeout = false;
+ });
+ pluginsController.queryPluginHTTPList().then((_) {
+ setState(() {
+ loading = false;
+ });
+ if (pluginsController.pluginHTTPList.isEmpty) {
+ setState(() {
+ timeout = true;
+ });
+ }
+ });
+ }
+ }
+
+ Widget get pluginHTTPListBody {
+ return Observer(builder: (context) {
+ return ListView.builder(
+ itemCount: pluginsController.pluginHTTPList.length,
+ itemBuilder: (context, index) {
+ return Card(
+ margin: const EdgeInsets.fromLTRB(8, 0, 8, 8),
+ child: ListTile(
+ title: Row(
+ children: [
+ Text(
+ pluginsController.pluginHTTPList[index].name,
+ style: const TextStyle(fontWeight: FontWeight.bold),
+ ),
+ ],
+ ),
+ subtitle: Row(
+ children: [
+ Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8.0, vertical: 1.0),
+ decoration: BoxDecoration(
+ color: Theme.of(context).colorScheme.secondary,
+ borderRadius: BorderRadius.circular(16.0),
+ ),
+ child: Text(
+ pluginsController.pluginHTTPList[index].version,
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.surface),
+ ),
+ ),
+ const SizedBox(
+ width: 5,
+ ),
+ Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8.0, vertical: 1.0),
+ decoration: BoxDecoration(
+ color: Theme.of(context).colorScheme.primary,
+ borderRadius: BorderRadius.circular(16.0),
+ ),
+ child: Text(
+ pluginsController.pluginHTTPList[index].useNativePlayer
+ ? "native"
+ : "webview",
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.surface),
+ ),
+ ),
+ ],
+ ),
+ trailing: TextButton(
+ onPressed: () async {
+ if (pluginsController.pluginStatus(
+ pluginsController.pluginHTTPList[index]) ==
+ 'install') {
+ try {
+ SmartDialog.showToast('导入中');
+ var pluginHTTPItem =
+ await pluginsController.queryPluginHTTP(
+ pluginsController.pluginHTTPList[index].name);
+ if (pluginHTTPItem != null) {
+ if (int.parse(pluginHTTPItem.api) > Api.apiLevel) {
+ SmartDialog.showToast('kazumi版本过低, 此规则不兼容当前版本');
+ return;
+ }
+ await pluginsController
+ .savePluginToJsonFile(pluginHTTPItem);
+ await pluginsController.loadPlugins();
+ SmartDialog.showToast('导入成功');
+ setState(() {});
+ }
+ } catch (e) {
+ SmartDialog.showToast('导入规则失败');
+ }
+ }
+ if (pluginsController.pluginStatus(
+ pluginsController.pluginHTTPList[index]) ==
+ 'update') {
+ try {
+ SmartDialog.showToast('更新中');
+ var pluginHTTPItem =
+ await pluginsController.queryPluginHTTP(
+ pluginsController.pluginHTTPList[index].name);
+ if (pluginHTTPItem != null) {
+ if (int.parse(pluginHTTPItem.api) > Api.apiLevel) {
+ SmartDialog.showToast('kazumi版本过低, 此规则不兼容当前版本');
+ return;
+ }
+ await pluginsController
+ .savePluginToJsonFile(pluginHTTPItem);
+ await pluginsController.loadPlugins();
+ SmartDialog.showToast('更新成功');
+ setState(() {});
+ }
+ } catch (e) {
+ SmartDialog.showToast('更新规则失败');
+ }
+ }
+ },
+ child: Text(pluginsController.pluginStatus(
+ pluginsController.pluginHTTPList[index]) ==
+ 'install'
+ ? '安装'
+ : (pluginsController.pluginStatus(
+ pluginsController.pluginHTTPList[index]) ==
+ 'installed')
+ ? '已安装'
+ : '更新'),
+ )),
+ );
+ },
+ );
+ });
+ }
+
+ Widget get timeoutWidget {
+ return Center(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text('啊咧(⊙.⊙) 无法访问远程仓库 ${enableGitProxy ? '镜像已启用' : '镜像已禁用'}'),
+ const SizedBox(
+ height: 10,
+ ),
+ FilledButton.tonal(
+ onPressed: () {
+ Modular.to.pushNamed('/tab/my/other');
+ },
+ child: Text(enableGitProxy ? '禁用镜像' : '启用镜像')),
+ const SizedBox(
+ height: 10,
+ ),
+ FilledButton.tonal(
+ onPressed: () {
+ _handleRefresh();
+ },
+ child: const Text('刷新'))
+ ],
+ ));
+ }
+
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -57,152 +220,21 @@ class _PluginShopPageState extends State<PluginShopPage> {
onBackPressed(context);
},
child: Scaffold(
- appBar: const SysAppBar(
- title: Text('规则仓库'),
+ appBar: SysAppBar(
+ title: const Text('规则仓库'),
+ actions: [
+ IconButton(
+ onPressed: () {
+ _handleRefresh();
+ },
+ icon: const Icon(Icons.refresh))
+ ],
),
- body: Observer(builder: (context) {
- return pluginsController.pluginHTTPList.isEmpty
- ? Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- '啊咧(⊙.⊙) 无法访问远程仓库 ${enableGitProxy ? '镜像已启用' : '镜像已禁用'}'),
- TextButton(
- onPressed: () {
- Modular.to.pushNamed('/tab/my/other');
- },
- child: Text(enableGitProxy ? '禁用镜像' : '启用镜像'))
- ],
- ),
- )
- : ListView.builder(
- itemCount: pluginsController.pluginHTTPList.length,
- itemBuilder: (context, index) {
- return Card(
- margin: const EdgeInsets.fromLTRB(8, 0, 8, 8),
- child: ListTile(
- title: Row(
- children: [
- Text(
- pluginsController.pluginHTTPList[index].name,
- style: const TextStyle(
- fontWeight: FontWeight.bold),
- ),
- ],
- ),
- subtitle: Row(
- children: [
- Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 8.0, vertical: 1.0),
- decoration: BoxDecoration(
- color:
- Theme.of(context).colorScheme.secondary,
- borderRadius: BorderRadius.circular(16.0),
- ),
- child: Text(
- pluginsController.pluginHTTPList[index].version,
- style: TextStyle(
- color: Theme.of(context)
- .colorScheme
- .surface),
- ),
- ),
- const SizedBox(
- width: 5,
- ),
- Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 8.0, vertical: 1.0),
- decoration: BoxDecoration(
- color: Theme.of(context).colorScheme.primary,
- borderRadius: BorderRadius.circular(16.0),
- ),
- child: Text(
- pluginsController
- .pluginHTTPList[index].useNativePlayer
- ? "native"
- : "webview",
- style: TextStyle(
- color: Theme.of(context)
- .colorScheme
- .surface),
- ),
- ),
- ],
- ),
- trailing: TextButton(
- onPressed: () async {
- if (pluginsController.pluginStatus(
- pluginsController
- .pluginHTTPList[index]) ==
- 'install') {
- try {
- SmartDialog.showToast('导入中');
- var pluginHTTPItem = await pluginsController
- .queryPluginHTTP(pluginsController
- .pluginHTTPList[index].name);
- if (pluginHTTPItem != null) {
- if (int.parse(pluginHTTPItem.api) >
- Api.apiLevel) {
- SmartDialog.showToast(
- 'kazumi版本过低, 此规则不兼容当前版本');
- return;
- }
- await pluginsController
- .savePluginToJsonFile(pluginHTTPItem);
- await pluginsController.loadPlugins();
- SmartDialog.showToast('导入成功');
- setState(() {});
- }
- } catch (e) {
- SmartDialog.showToast('导入规则失败');
- }
- }
- if (pluginsController.pluginStatus(
- pluginsController
- .pluginHTTPList[index]) ==
- 'update') {
- try {
- SmartDialog.showToast('更新中');
- var pluginHTTPItem = await pluginsController
- .queryPluginHTTP(pluginsController
- .pluginHTTPList[index].name);
- if (pluginHTTPItem != null) {
- if (int.parse(pluginHTTPItem.api) >
- Api.apiLevel) {
- SmartDialog.showToast(
- 'kazumi版本过低, 此规则不兼容当前版本');
- return;
- }
- await pluginsController
- .savePluginToJsonFile(pluginHTTPItem);
- await pluginsController.loadPlugins();
- SmartDialog.showToast('更新成功');
- setState(() {});
- }
- } catch (e) {
- SmartDialog.showToast('更新规则失败');
- }
- }
- },
- child: Text(pluginsController.pluginStatus(
- pluginsController
- .pluginHTTPList[index]) ==
- 'install'
- ? '安装'
- : (pluginsController.pluginStatus(
- pluginsController
- .pluginHTTPList[index]) ==
- 'installed')
- ? '已安装'
- : '更新'),
- )),
- );
- },
- );
- }),
+ body: loading
+ ? (const Center(child: CircularProgressIndicator()))
+ : (pluginsController.pluginHTTPList.isEmpty
+ ? timeoutWidget
+ : pluginHTTPListBody),
),
);
}
diff --git a/lib/pages/settings/other_settings.dart b/lib/pages/settings/other_settings.dart
index d2b8b065..8499c30b 100644
--- a/lib/pages/settings/other_settings.dart
+++ b/lib/pages/settings/other_settings.dart
@@ -58,7 +58,6 @@ class _OtherSettingsPageState extends State<OtherSettingsPage> {
title: 'Github镜像',
subTitle: '使用镜像访问规则托管仓库',
setKey: SettingBoxKey.enableGitProxy,
- needReboot: true,
defaultVal: false,
),
),
diff --git a/lib/plugins/plugins_controller.dart b/lib/plugins/plugins_controller.dart
index 90064926..f5ae4e74 100644
--- a/lib/plugins/plugins_controller.dart
+++ b/lib/plugins/plugins_controller.dart
@@ -123,6 +123,7 @@ Future<void> deletePluginJsonFile(Plugin plugin) async {
}
Future<void> queryPluginHTTPList() async {
+ pluginHTTPList.clear();
var pluginHTTPListRes = await PluginHTTP.getPluginList();
pluginHTTPList.addAll(pluginHTTPListRes);
}
diff --git a/lib/request/interceptor.dart b/lib/request/interceptor.dart
index 6225f651..a59bf00a 100644
--- a/lib/request/interceptor.dart
+++ b/lib/request/interceptor.dart
@@ -7,13 +7,15 @@ import 'package:connectivity_plus/connectivity_plus.dart';
class ApiInterceptor extends Interceptor {
static Box setting = GStorage.setting;
- bool enableGitProxy =
- setting.get(SettingBoxKey.enableGitProxy, defaultValue: false);
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
// Github mirror
- if (options.path.contains('github') && enableGitProxy) {
- options.path = Api.gitMirror + options.path;
+ if (options.path.contains('github')) {
+ bool enableGitProxy =
+ setting.get(SettingBoxKey.enableGitProxy, defaultValue: false);
+ if (enableGitProxy) {
+ options.path = Api.gitMirror + options.path;
+ }
}
handler.next(options);
}