基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
refactor(about): redesign the about page
Prediditf26ca74f09f0
diff --git a/lib/bean/widget/state_presentation.dart b/lib/bean/widget/state_presentation.dartindex 7a6b1b4a..89b58d23 100644--- a/lib/bean/widget/state_presentation.dart+++ b/lib/bean/widget/state_presentation.dart@@ -51,6 +51,7 @@ class StateActionButton extends StatelessWidget {required this.onPressed,required this.text,this.icon,+ this.reserveText,}) : _tonal = false;const StateActionButton.tonal({@@ -58,11 +59,15 @@ class StateActionButton extends StatelessWidget {required this.onPressed,required this.text,this.icon,+ this.reserveText,}) : _tonal = true;final VoidCallback? onPressed;final String text;final IconData? icon;++ /// Reserves label space for a longer status without changing button size.+ final String? reserveText;final bool _tonal;@override@@ -80,11 +85,26 @@ class StateActionButton extends StatelessWidget {: const Duration(milliseconds: 200),);final button = _tonal ? FilledButton.tonalIcon : FilledButton.icon;+ final label = Text(text, textAlign: TextAlign.center);return button(onPressed: onPressed,style: style,icon: icon == null ? null : Icon(icon, size: 20),- label: Text(text, textAlign: TextAlign.center),+ label: reserveText == null+ ? label+ : Stack(+ alignment: Alignment.center,+ children: [+ Visibility(+ visible: false,+ maintainSize: true,+ maintainState: true,+ maintainAnimation: true,+ child: Text(reserveText!, textAlign: TextAlign.center),+ ),+ label,+ ],+ ),);}}diff --git a/lib/pages/about/about_module.dart b/lib/pages/about/about_module.dartindex 0d2ca425..6ea07498 100644--- a/lib/pages/about/about_module.dart+++ b/lib/pages/about/about_module.dart@@ -1,7 +1,7 @@import 'package:flutter/material.dart';import 'package:flutter_modular/flutter_modular.dart';import 'package:kazumi/pages/about/about_page.dart';-import 'package:kazumi/pages/logs/logs_page.dart';+import 'package:kazumi/pages/about/credits_page.dart';import 'package:kazumi/pages/my/my_controller.dart';import 'package:kazumi/request/config/api_endpoints.dart';@@ -12,16 +12,16 @@ final aboutModule = createModule(..route('/',child: (context, state) => AboutPage(- controller: inject<MyController>(),+ onCheckUpdate: inject<MyController>().checkUpdate,),)- ..route('/logs', child: (context, state) => const LogsPage())+ ..route('/credits', child: (context, state) => const CreditsPage())..route('/license',child: (context, state) => const LicensePage(applicationName: 'Kazumi',applicationVersion: ApiEndpoints.version,- applicationLegalese: '开源许可证',+ applicationLegalese: 'Kazumi · GNU General Public License v3.0',),);},diff --git a/lib/pages/about/about_page.dart b/lib/pages/about/about_page.dartindex cbc70d5d..99d599db 100644--- a/lib/pages/about/about_page.dart+++ b/lib/pages/about/about_page.dart@@ -1,352 +1,154 @@-import 'dart:io';--import 'package:kazumi/bean/settings/settings_list.dart';import 'package:flutter/material.dart';-import 'package:flutter_modular/flutter_modular.dart';+import 'package:kazumi/bean/settings/settings_detail_scaffold.dart';-import 'package:kazumi/bean/dialog/dialog_helper.dart';-import 'package:kazumi/pages/my/my_controller.dart';+import 'package:kazumi/bean/widget/content_section.dart';+import 'package:kazumi/pages/about/about_widgets.dart';import 'package:kazumi/request/config/api_endpoints.dart';-import 'package:kazumi/utils/dandan_credentials.dart';-import 'package:kazumi/services/storage/storage.dart';-import 'package:path_provider/path_provider.dart';-import 'package:url_launcher/url_launcher.dart';-import 'package:kazumi/utils/device.dart';-class AboutPage extends StatefulWidget {- const AboutPage({- super.key,- required this.controller,- });+class AboutPage extends StatelessWidget {+ const AboutPage({super.key, required this.onCheckUpdate});- final MyController controller;+ final Future<bool> Function() onCheckUpdate;@override- State<AboutPage> createState() => _AboutPageState();+ Widget build(BuildContext context) => SettingsDetailScaffold(+ title: const Text('关于'),+ body: AboutContent(+ children: [+ _ProjectHeader(onCheckUpdate: onCheckUpdate),+ const SizedBox(height: 24),+ LayoutBuilder(builder: (context, constraints) {+ final sections = [+ ContentSection.group(+ title: '项目',+ children: const [+ AboutLinkTile(+ icon: Icons.code_rounded,+ title: '源代码',+ url: ApiEndpoints.sourceUrl,+ ),+ AboutLinkTile(+ icon: Icons.language_rounded,+ title: '项目主页',+ url: ApiEndpoints.projectUrl,+ ),+ AboutLinkTile(+ icon: Icons.bug_report_rounded,+ title: '问题反馈',+ url: '${ApiEndpoints.sourceUrl}/issues',+ ),+ AboutLinkTile(+ icon: Icons.forum_rounded,+ title: 'Telegram',+ url: ApiEndpoints.telegramGroup,+ ),+ ],+ ),+ ContentSection.group(+ title: '开源',+ children: [+ const AboutLinkTile(+ icon: Icons.handshake_outlined,+ title: '贡献指南',+ url:+ '${ApiEndpoints.sourceUrl}/blob/main/static/doc/CONTRIBUTING.md',+ ),+ const AboutLinkTile.route(+ icon: Icons.favorite_outline_rounded,+ title: '致谢',+ route: '/settings/about/credits',+ ),+ const AboutLinkTile(+ icon: Icons.balance_rounded,+ title: 'GPL-3.0 许可证',+ url: '${ApiEndpoints.sourceUrl}/blob/main/LICENSE',+ ),+ const AboutLinkTile.route(+ icon: Icons.description_outlined,+ title: '第三方许可证',+ route: '/settings/about/license',+ ),+ ],+ ),+ ];+ if (constraints.maxWidth >= 640 &&+ MediaQuery.textScalerOf(context).scale(14) < 21) {+ return Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Expanded(child: sections[0]),+ const SizedBox(width: 16),+ Expanded(child: sections[1]),+ ],+ );+ }+ return Column(+ children: [+ sections[0],+ const SizedBox(height: 24),+ sections[1]+ ],+ );+ }),+ ],+ ),+ );}-class _AboutPageState extends State<AboutPage> {- final exitBehaviorTitles = <String>['退出 Kazumi', '最小化至托盘', '每次都询问'];- late dynamic defaultDanmakuArea;- late dynamic defaultThemeMode;- late dynamic defaultThemeColor;- late int exitBehavior = GStorage.getSetting(SettingsKeys.exitBehavior);- late bool autoUpdate;- late bool checkPluginUpdateOnStartup;- double _cacheSizeMB = -1;- MyController get myController => widget.controller;- final MenuController menuController = MenuController();-- @override- void initState() {- super.initState();- autoUpdate = GStorage.getSetting(SettingsKeys.autoUpdate);- checkPluginUpdateOnStartup =- GStorage.getSetting(SettingsKeys.checkPluginUpdateOnStartup);- _getCacheSize();- }-- void onBackPressed(BuildContext context) {- if (KazumiDialog.observer.hasKazumiDialog) {- KazumiDialog.dismiss();- return;- }- }-- Future<Directory> _getCacheDir() async {- Directory tempDir = await getTemporaryDirectory();- return Directory('${tempDir.path}/libCachedImageData');- }-- Future<void> _getCacheSize() async {- Directory cacheDir = await _getCacheDir();-- if (await cacheDir.exists()) {- int totalSizeBytes = await _getTotalSizeOfFilesInDir(cacheDir);- double totalSizeMB = (totalSizeBytes / (1024 * 1024));-- if (mounted) {- setState(() {- _cacheSizeMB = totalSizeMB;- });- }- } else {- if (mounted) {- setState(() {- _cacheSizeMB = 0.0;- });- }- }- }-- Future<int> _getTotalSizeOfFilesInDir(final Directory directory) async {- final List<FileSystemEntity> children = directory.listSync();- int total = 0;-- try {- for (final FileSystemEntity child in children) {- if (child is File) {- final int length = await child.length();- total += length;- } else if (child is Directory) {- total += await _getTotalSizeOfFilesInDir(child);- }- }- } catch (_) {}- return total;- }-- Future<void> _clearCache() async {- final Directory libCacheDir = await _getCacheDir();- await libCacheDir.delete(recursive: true);- _getCacheSize();- }+class _ProjectHeader extends StatelessWidget {+ const _ProjectHeader({required this.onCheckUpdate});- void _showCacheDialog() {- KazumiDialog.show(- builder: (context) {- return AlertDialog(- title: const Text('缓存管理'),- content: const Text('缓存为番剧封面, 清除后加载时需要重新下载,确认要清除缓存吗?'),- actions: [- TextButton(- onPressed: () {- KazumiDialog.dismiss();- },- child: Text(- '取消',- style: TextStyle(color: Theme.of(context).colorScheme.outline),- ),- ),- TextButton(- onPressed: () async {- try {- _clearCache();- } catch (_) {}- KazumiDialog.dismiss();- },- child: const Text('确认'),- ),- ],- );- },- );- }+ final Future<bool> Function() onCheckUpdate;@overrideWidget build(BuildContext context) {- return PopScope(- canPop: true,- onPopInvokedWithResult: (bool didPop, Object? result) async {- onBackPressed(context);- },- child: SettingsDetailScaffold(- title: const Text('关于'),- body: SettingsList(- sections: [- SettingsSection(- title: Text('开源'),- tiles: [- SettingsTile(- leading: Icons.gavel_rounded,- onPressed: (_) {- context.pushNamed('/settings/about/license');- },- title: Text('开源许可证'),- description: Text('查看所有开源许可证'),- ),- ],- ),- SettingsSection(- title: Text('外部链接'),- tiles: [- SettingsTile(- leading: Icons.home_rounded,- onPressed: (_) {- launchUrl(Uri.parse(ApiEndpoints.projectUrl),- mode: LaunchMode.externalApplication);- },- title: Text('项目主页'),- ),- SettingsTile(- leading: Icons.code_rounded,- onPressed: (_) {- launchUrl(Uri.parse(ApiEndpoints.sourceUrl),- mode: LaunchMode.externalApplication);- },- title: Text('代码仓库'),- value: Text('Github'),- ),- SettingsTile(- leading: Icons.brush_rounded,- onPressed: (_) {- launchUrl(Uri.parse(ApiEndpoints.iconUrl),- mode: LaunchMode.externalApplication);- },- title: Text('图标创作'),- value: Text('Pixiv'),- ),- SettingsTile(- leading: Icons.menu_book_rounded,- onPressed: (_) {- launchUrl(Uri.parse(ApiEndpoints.bangumiIndex),- mode: LaunchMode.externalApplication);- },- title: Text('番剧索引'),- value: Text('Bangumi'),- ),- SettingsTile(- leading: Icons.image_search_rounded,- onPressed: (_) {- launchUrl(Uri.parse('https://trace.moe'),- mode: LaunchMode.externalApplication);- },- title: Text('以图搜番'),- value: Text('trace.moe'),- ),- SettingsTile(- leading: Icons.subtitles_rounded,- onPressed: (_) {- launchUrl(Uri.parse(ApiEndpoints.dandanIndex),- mode: LaunchMode.externalApplication);- },- title: Text('弹幕来源'),- description: Text('ID: ${dandanCredentials['id']}'),- value: Text('弹弹play开放平台'),- ),- ],- ),- SettingsSection(- title: Text('社区'),- tiles: [- SettingsTile(- leading: Icons.send_rounded,- onPressed: (_) {- launchUrl(Uri.parse(ApiEndpoints.telegramGroup),- mode: LaunchMode.externalApplication);- },- title: Text('Telegram'),- value: Text('点击加入'),- ),- ],- ),- if (isDesktop()) // 之后如果有非桌面平台的新选项可以移除- SettingsSection(- title: Text('默认行为'),- tiles: [- SettingsTile(- leading: Icons.exit_to_app_rounded,- onPressed: (_) {- if (menuController.isOpen) {- menuController.close();- } else {- menuController.open();- }- },- title: Text('关闭时'),- value: MenuAnchor(- consumeOutsideTap: true,- controller: menuController,- builder: (_, __, ___) {- return Text(exitBehaviorTitles[exitBehavior]);- },- menuChildren: [- for (int i = 0; i < 3; i++)- MenuItemButton(- requestFocusOnHover: false,- onPressed: () {- exitBehavior = i;- GStorage.putSetting(SettingsKeys.exitBehavior, i);- setState(() {});- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- exitBehaviorTitles[i],- style: TextStyle(- color: i == exitBehavior- ? Theme.of(context).colorScheme.primary- : null,- ),- ),- ),- ),- ),- ],- ),- ),- ],+ final theme = Theme.of(context);+ final colors = theme.colorScheme;+ return Padding(+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Semantics(+ header: true,+ child: Text(+ 'Kazumi',+ style: theme.textTheme.displayMedium?.copyWith(+ color: colors.primary,+ fontWeight: FontWeight.w600,),- SettingsSection(- title: Text('存储与日志'),- tiles: [- SettingsTile(- leading: Icons.receipt_long_rounded,- onPressed: (_) {- context.pushNamed('/settings/about/logs');- },- title: Text('错误日志'),- ),- SettingsTile(- leading: Icons.cleaning_services_rounded,- onPressed: (_) {- _showCacheDialog();- },- title: Text('清除缓存'),- value: _cacheSizeMB == -1- ? Text('统计中...')- : Text('${_cacheSizeMB.toStringAsFixed(2)}MB'),- ),- ],),- SettingsSection(- title: Text('应用更新'),- tiles: [- SettingsTile.switchTile(- leading: Icons.update_rounded,- onToggle: (value) async {- autoUpdate = value ?? !autoUpdate;- await GStorage.putSetting(- SettingsKeys.autoUpdate, autoUpdate);- setState(() {});- },- title: Text('启动时检查应用更新'),- initialValue: autoUpdate,- ),- SettingsTile(- leading: Icons.system_update_rounded,- onPressed: (_) {- myController.checkUpdate();- },- title: Text('检查应用更新'),- value: Text('当前版本 ${ApiEndpoints.version}'),- ),- ],+ ),+ const SizedBox(height: 4),+ Text(+ ApiEndpoints.version,+ style: theme.textTheme.bodyMedium?.copyWith(+ color: colors.onSurfaceVariant,),- SettingsSection(- title: Text('规则更新'),- tiles: [- SettingsTile.switchTile(- leading: Icons.extension_rounded,- onToggle: (value) async {- checkPluginUpdateOnStartup =- value ?? !checkPluginUpdateOnStartup;- await GStorage.putSetting(- SettingsKeys.checkPluginUpdateOnStartup,- checkPluginUpdateOnStartup,- );- setState(() {});- },- title: Text('启动时检查规则更新'),- initialValue: checkPluginUpdateOnStartup,+ ),+ const SizedBox(height: 12),+ Text(+ '基于自定义规则的开源番剧应用',+ style: theme.textTheme.bodyLarge,+ ),+ const SizedBox(height: 20),+ Wrap(+ spacing: 8,+ runSpacing: 8,+ crossAxisAlignment: WrapCrossAlignment.center,+ children: [+ CheckUpdateButton(onCheckUpdate: onCheckUpdate),+ TextButton(+ style: TextButton.styleFrom(minimumSize: const Size(48, 48)),+ onPressed: () => openAboutLink(+ context,+ '${ApiEndpoints.sourceUrl}/releases',),- ],- ),- ],- ),+ child: const Text('更新日志'),+ ),+ ],+ ),+ ],),);}diff --git a/lib/pages/about/about_widgets.dart b/lib/pages/about/about_widgets.dartnew file mode 100644index 00000000..2c4d1266--- /dev/null+++ b/lib/pages/about/about_widgets.dart@@ -0,0 +1,158 @@+import 'package:flutter/material.dart';+import 'package:flutter_modular/flutter_modular.dart';+import 'package:url_launcher/url_launcher.dart';++import 'package:kazumi/bean/widget/split_list_row.dart';+import 'package:kazumi/bean/widget/state_presentation.dart';++void _showMessage(BuildContext context, String message) {+ ScaffoldMessenger.of(context)+ ..hideCurrentSnackBar()+ ..showSnackBar(SnackBar(content: Text(message)));+}++Future<void> openAboutLink(BuildContext context, String url) async {+ try {+ if (await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication)) {+ return;+ }+ } catch (_) {}+ if (context.mounted) _showMessage(context, '无法打开链接,请稍后重试');+}++class AboutContent extends StatelessWidget {+ const AboutContent({super.key, required this.children});++ final List<Widget> children;++ @override+ Widget build(BuildContext context) => SafeArea(+ top: false,+ child: SingleChildScrollView(+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 32),+ child: Center(+ child: ConstrainedBox(+ constraints: const BoxConstraints(maxWidth: 880),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: children,+ ),+ ),+ ),+ ),+ );+}++class AboutLinkTile extends StatelessWidget {+ const AboutLinkTile({+ super.key,+ required this.icon,+ required this.title,+ required String url,+ this.subtitle,+ }) : _url = url,+ _route = null;++ const AboutLinkTile.route({+ super.key,+ required this.icon,+ required this.title,+ required String route,+ this.subtitle,+ }) : _route = route,+ _url = null;++ final IconData icon;+ final String title;+ final String? subtitle;+ final String? _url;+ final String? _route;++ @override+ Widget build(BuildContext context) {+ final theme = Theme.of(context);+ final colors = theme.colorScheme;+ return Semantics(+ link: _url != null,+ child: InkWell(+ onTap: () => _url != null+ ? openAboutLink(context, _url)+ : context.pushNamed(_route!),+ onHighlightChanged: SplitListRow.pressReporterOf(context),+ child: Padding(+ padding: const EdgeInsets.all(16),+ child: Row(+ children: [+ StateIconBadge(+ icon: icon,+ size: 36,+ iconSize: 20,+ backgroundColor: colors.secondaryContainer,+ foregroundColor: colors.onSecondaryContainer,+ ),+ const SizedBox(width: 16),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(title, style: theme.textTheme.titleMedium),+ if (subtitle != null) ...[+ const SizedBox(height: 4),+ Text(+ subtitle!,+ style: theme.textTheme.bodyMedium?.copyWith(+ color: colors.onSurfaceVariant,+ ),+ ),+ ],+ ],+ ),+ ),+ const SizedBox(width: 12),+ Icon(+ _url == null+ ? Icons.chevron_right_rounded+ : Icons.open_in_new_rounded,+ size: 20,+ color: colors.onSurfaceVariant,+ ),+ ],+ ),+ ),+ ),+ );+ }+}++class CheckUpdateButton extends StatefulWidget {+ const CheckUpdateButton({super.key, required this.onCheckUpdate});++ final Future<bool> Function() onCheckUpdate;++ @override+ State<CheckUpdateButton> createState() => _CheckUpdateButtonState();+}++class _CheckUpdateButtonState extends State<CheckUpdateButton> {+ bool _checking = false;++ Future<void> _check() async {+ if (_checking) return;+ setState(() => _checking = true);+ try {+ await widget.onCheckUpdate();+ } catch (_) {+ if (mounted) _showMessage(context, '检查更新失败,请稍后重试');+ } finally {+ if (mounted) setState(() => _checking = false);+ }+ }++ @override+ Widget build(BuildContext context) => StateActionButton(+ onPressed: _checking ? null : _check,+ text: _checking ? '正在检查…' : '检查更新',+ reserveText: '正在检查…',+ icon: Icons.update_rounded,+ );+}diff --git a/lib/pages/about/credits_page.dart b/lib/pages/about/credits_page.dartnew file mode 100644index 00000000..71d06611--- /dev/null+++ b/lib/pages/about/credits_page.dart@@ -0,0 +1,107 @@+import 'package:flutter/material.dart';++import 'package:kazumi/bean/settings/settings_detail_scaffold.dart';+import 'package:kazumi/bean/widget/content_section.dart';+import 'package:kazumi/pages/about/about_widgets.dart';+import 'package:kazumi/request/config/api_endpoints.dart';++class CreditsPage extends StatelessWidget {+ const CreditsPage({super.key});++ @override+ Widget build(BuildContext context) => SettingsDetailScaffold(+ title: const Text('致谢'),+ body: AboutContent(+ children: [+ ContentSection.group(+ title: '贡献',+ children: const [+ AboutLinkTile(+ icon: Icons.people_outline_rounded,+ title: '贡献者',+ url: '${ApiEndpoints.sourceUrl}/graphs/contributors',+ ),+ AboutLinkTile(+ icon: Icons.brush_rounded,+ title: '图标作者',+ subtitle: 'Pixiv',+ url: ApiEndpoints.iconUrl,+ ),+ ],+ ),+ const SizedBox(height: 24),+ ContentSection.group(+ title: '服务',+ children: const [+ AboutLinkTile(+ icon: Icons.menu_book_rounded,+ title: 'Bangumi',+ subtitle: '番剧信息',+ url: ApiEndpoints.bangumiIndex,+ ),+ AboutLinkTile(+ icon: Icons.subtitles_rounded,+ title: '弹弹play',+ subtitle: '弹幕',+ url: ApiEndpoints.dandanIndex,+ ),+ AboutLinkTile(+ icon: Icons.image_search_rounded,+ title: 'trace.moe',+ subtitle: '以图搜番',+ url: 'https://trace.moe',+ ),+ ],+ ),+ const SizedBox(height: 24),+ ContentSection.group(+ title: '开源项目',+ children: const [+ AboutLinkTile(+ icon: Icons.flutter_dash_rounded,+ title: 'Flutter',+ subtitle: '应用框架',+ url: 'https://flutter.dev',+ ),+ AboutLinkTile(+ icon: Icons.play_circle_outline_rounded,+ title: 'media-kit',+ subtitle: '视频播放',+ url: 'https://github.com/media-kit/media-kit',+ ),+ AboutLinkTile(+ icon: Icons.auto_awesome_rounded,+ title: 'Anime4K',+ subtitle: '实时超分辨率',+ url: 'https://github.com/bloc97/Anime4K',+ ),+ AboutLinkTile(+ icon: Icons.sync_rounded,+ title: 'Syncplay',+ subtitle: '播放同步',+ url: 'https://github.com/Syncplay/syncplay',+ ),+ AboutLinkTile(+ icon: Icons.account_tree_rounded,+ title: 'XpathSelector',+ subtitle: 'XPath 解析',+ url: 'https://github.com/simonkimi/xpath_selector',+ ),+ AboutLinkTile(+ icon: Icons.video_settings_rounded,+ title: 'avbuild',+ subtitle: '非标准视频流支持',+ url: 'https://github.com/wang-bin/avbuild',+ ),+ AboutLinkTile(+ icon: Icons.storage_rounded,+ title: 'Hive CE',+ subtitle: '本地存储',+ url: 'https://github.com/IO-Design-Team/hive_ce',+ ),+ ],+ ),+ ],+ ),+ );+}diff --git a/lib/pages/settings/interface_settings.dart b/lib/pages/settings/interface_settings.dartindex 010addd8..9091543b 100644--- a/lib/pages/settings/interface_settings.dart+++ b/lib/pages/settings/interface_settings.dart@@ -2,6 +2,7 @@ import 'package:kazumi/bean/settings/settings_list.dart';import 'package:flutter/material.dart';import 'package:kazumi/bean/settings/settings_detail_scaffold.dart';import 'package:kazumi/services/storage/storage.dart';+import 'package:kazumi/utils/device.dart';class InterfaceSettingsPage extends StatefulWidget {const InterfaceSettingsPage({super.key});@@ -13,6 +14,8 @@ class InterfaceSettingsPage extends StatefulWidget {class _InterfaceSettingsPageState extends State<InterfaceSettingsPage> {late bool showRating;late String defaultPage;+ int _exitBehavior = GStorage.getSetting(SettingsKeys.exitBehavior);+ static const _exitBehaviorTitles = ['退出 Kazumi', '最小化至托盘', '每次都询问'];final MenuController defaultPageMenuController = MenuController();static const Map<String, String> defaultPageMap = {@@ -100,6 +103,38 @@ class _InterfaceSettingsPageState extends State<InterfaceSettingsPage> {initialValue: showRating,),]),+ if (isDesktop())+ SettingsSection(+ title: const Text('窗口行为'),+ tiles: [+ SettingsTile(+ leading: Icons.exit_to_app_rounded,+ title: const Text('关闭窗口时'),+ description: Padding(+ padding: const EdgeInsets.only(top: 8),+ child: DropdownButton<int>(+ value: _exitBehavior.clamp(+ 0, _exitBehaviorTitles.length - 1),+ isExpanded: true,+ borderRadius: BorderRadius.circular(16),+ underline: const SizedBox.shrink(),+ items: [+ for (var i = 0; i < _exitBehaviorTitles.length; i++)+ DropdownMenuItem(+ value: i,+ child: Text(_exitBehaviorTitles[i]),+ ),+ ],+ onChanged: (value) {+ if (value == null) return;+ setState(() => _exitBehavior = value);+ GStorage.putSetting(SettingsKeys.exitBehavior, value);+ },+ ),+ ),+ ),+ ],+ ),],),);diff --git a/lib/pages/settings/settings_module.dart b/lib/pages/settings/settings_module.dartindex 43a44782..b218c953 100644--- a/lib/pages/settings/settings_module.dart+++ b/lib/pages/settings/settings_module.dart@@ -3,6 +3,7 @@ import 'package:kazumi/pages/about/about_module.dart';import 'package:kazumi/pages/bangumi/bangumi_module.dart';import 'package:kazumi/pages/download/download_page_module.dart';import 'package:kazumi/pages/history/history_module.dart';+import 'package:kazumi/pages/logs/logs_page.dart';import 'package:kazumi/pages/plugin_editor/plugin_module.dart';import 'package:kazumi/pages/settings/danmaku/danmaku_module.dart';import 'package:kazumi/pages/settings/decoder_settings.dart';@@ -14,8 +15,10 @@ import 'package:kazumi/pages/settings/player_settings.dart';import 'package:kazumi/pages/settings/proxy/proxy_module.dart';import 'package:kazumi/pages/settings/renderer_settings.dart';import 'package:kazumi/pages/settings/settings_page.dart';+import 'package:kazumi/pages/settings/storage_settings.dart';import 'package:kazumi/pages/settings/super_resolution_settings.dart';import 'package:kazumi/pages/settings/theme_settings_page.dart';+import 'package:kazumi/pages/settings/update_settings.dart';import 'package:kazumi/pages/webdav_editor/webdav_module.dart';final settingsModule = createModule(@@ -23,6 +26,13 @@ final settingsModule = createModule(register: (c) {c..route('/', child: (context, state) => const SettingsPage())+ ..route(+ '/update',+ child: (context, state) => const UpdateSettingsPage(),+ )+ ..route('/storage',+ child: (context, state) => const StorageSettingsPage())+ ..route('/storage/logs', child: (context, state) => const LogsPage())..route('/theme', child: (context, state) => const ThemeSettingsPage())..route('/theme/display',diff --git a/lib/pages/settings/settings_page.dart b/lib/pages/settings/settings_page.dartindex 9432c2bb..4c4588b9 100644--- a/lib/pages/settings/settings_page.dart+++ b/lib/pages/settings/settings_page.dart@@ -14,7 +14,9 @@ import 'package:kazumi/pages/settings/interface_settings.dart';import 'package:kazumi/pages/settings/keyboard_settings.dart';import 'package:kazumi/pages/settings/player_settings.dart';import 'package:kazumi/pages/settings/proxy/proxy_settings_page.dart';+import 'package:kazumi/pages/settings/storage_settings.dart';import 'package:kazumi/pages/settings/theme_settings_page.dart';+import 'package:kazumi/pages/settings/update_settings.dart';import 'package:kazumi/pages/webdav_editor/webdav_setting.dart';import 'package:kazumi/plugins/plugins_controller.dart';import 'package:kazumi/utils/constants.dart';@@ -101,7 +103,7 @@ final List<_SettingsGroup> _settingsGroups = [_SettingsCategory(id: 'interface',label: '界面设置',- description: '启动页与展示信息',+ description: '启动、窗口行为与展示信息',icon: Icons.pages_rounded,builder: (_) => const InterfaceSettingsPage(),),@@ -124,12 +126,28 @@ final List<_SettingsGroup> _settingsGroups = [_SettingsGroup(title: '其他',categories: [+ _SettingsCategory(+ id: 'update',+ label: '更新设置',+ description: '应用与规则更新',+ icon: Icons.update_rounded,+ builder: (_) => const UpdateSettingsPage(),+ ),+ _SettingsCategory(+ id: 'storage',+ label: '存储与日志',+ description: '图片缓存与错误日志',+ icon: Icons.storage_rounded,+ builder: (_) => const StorageSettingsPage(),+ ),_SettingsCategory(id: 'about',label: '关于',- description: '版本、日志与开源许可',+ description: '版本与开源信息',icon: Icons.info_outline_rounded,- builder: (_) => AboutPage(controller: inject<MyController>()),+ builder: (_) => AboutPage(+ onCheckUpdate: inject<MyController>().checkUpdate,+ ),),],),diff --git a/lib/pages/settings/storage_settings.dart b/lib/pages/settings/storage_settings.dartnew file mode 100644index 00000000..cfaf4558--- /dev/null+++ b/lib/pages/settings/storage_settings.dart@@ -0,0 +1,115 @@+import 'package:flutter/material.dart';+import 'package:flutter_modular/flutter_modular.dart';++import 'package:kazumi/bean/settings/settings_detail_scaffold.dart';+import 'package:kazumi/bean/settings/settings_list.dart';+import 'package:kazumi/services/storage/image_cache_service.dart';++class StorageSettingsPage extends StatefulWidget {+ const StorageSettingsPage({super.key});++ @override+ State<StorageSettingsPage> createState() => _StorageSettingsPageState();+}++class _StorageSettingsPageState extends State<StorageSettingsPage> {+ final _cache = ImageCacheService();+ late Future<int> _cacheSize = _cache.sizeInBytes();+ bool _clearing = false;++ void _refreshSize() => setState(() => _cacheSize = _cache.sizeInBytes());++ void _message(String message) {+ ScaffoldMessenger.of(context)+ ..hideCurrentSnackBar()+ ..showSnackBar(SnackBar(content: Text(message)));+ }++ Future<void> _confirmClear() async {+ if (_clearing) return;+ final confirmed = await showDialog<bool>(+ context: context,+ builder: (context) => AlertDialog(+ icon: const Icon(Icons.cleaning_services_rounded),+ title: const Text('清除图片缓存?'),+ content: const Text('图片会在下次加载时重新下载。视频、记录和设置不会删除。'),+ actions: [+ TextButton(+ onPressed: () => Navigator.of(context).pop(false),+ child: const Text('取消'),+ ),+ FilledButton(+ onPressed: () => Navigator.of(context).pop(true),+ child: const Text('清除缓存'),+ ),+ ],+ ),+ );+ if (confirmed != true || !mounted) return;+ setState(() => _clearing = true);+ try {+ await _cache.clear();+ if (!mounted) return;+ _message('图片缓存已清除');+ _refreshSize();+ } catch (_) {+ if (mounted) _message('清除失败,请稍后重试');+ } finally {+ if (mounted) setState(() => _clearing = false);+ }+ }++ String _cacheDescription(AsyncSnapshot<int> snapshot) {+ if (_clearing) return '正在清除…';+ if (snapshot.connectionState != ConnectionState.done) return '正在统计…';+ if (snapshot.hasError) return '统计失败';+ return '${(snapshot.requireData / (1024 * 1024)).toStringAsFixed(2)} MB';+ }++ @override+ Widget build(BuildContext context) => SettingsDetailScaffold(+ title: const Text('存储与日志'),+ body: FutureBuilder<int>(+ future: _cacheSize,+ builder: (context, snapshot) => SettingsList(+ sections: [+ SettingsSection(+ title: const Text('缓存'),+ tiles: [+ SettingsTile(+ leading: Icons.image_outlined,+ title: const Text('清除图片缓存'),+ description: Text(_cacheDescription(snapshot)),+ enabled: snapshot.connectionState == ConnectionState.done &&+ !_clearing,+ onPressed: (_) => _confirmClear(),+ trailing:+ snapshot.connectionState == ConnectionState.done &&+ snapshot.hasError &&+ !_clearing+ ? IconButton(+ tooltip: '重新统计',+ onPressed: _refreshSize,+ icon: const Icon(Icons.refresh_rounded),+ )+ : const Icon(Icons.cleaning_services_rounded),+ ),+ ],+ ),+ SettingsSection(+ title: const Text('诊断'),+ tiles: [+ SettingsTile(+ leading: Icons.receipt_long_rounded,+ title: const Text('错误日志'),+ trailing: const Icon(Icons.chevron_right_rounded),+ onPressed: (_) =>+ context.pushNamed('/settings/storage/logs'),+ ),+ ],+ ),+ ],+ ),+ ),+ );+}diff --git a/lib/pages/settings/update_settings.dart b/lib/pages/settings/update_settings.dartnew file mode 100644index 00000000..04781a31--- /dev/null+++ b/lib/pages/settings/update_settings.dart@@ -0,0 +1,53 @@+import 'package:flutter/material.dart';++import 'package:kazumi/bean/settings/settings_detail_scaffold.dart';+import 'package:kazumi/bean/settings/settings_list.dart';+import 'package:kazumi/services/storage/storage.dart';++class UpdateSettingsPage extends StatefulWidget {+ const UpdateSettingsPage({super.key});++ @override+ State<UpdateSettingsPage> createState() => _UpdateSettingsPageState();+}++class _UpdateSettingsPageState extends State<UpdateSettingsPage> {+ bool _autoUpdate = GStorage.getSetting(SettingsKeys.autoUpdate);+ bool _pluginUpdate =+ GStorage.getSetting(SettingsKeys.checkPluginUpdateOnStartup);++ @override+ Widget build(BuildContext context) => SettingsDetailScaffold(+ title: const Text('更新设置'),+ body: SettingsList(+ sections: [+ SettingsSection(+ title: const Text('启动时检查更新'),+ tiles: [+ SettingsTile.switchTile(+ leading: Icons.update_rounded,+ title: const Text('应用更新'),+ initialValue: _autoUpdate,+ onToggle: (value) {+ setState(() => _autoUpdate = value ?? !_autoUpdate);+ GStorage.putSetting(SettingsKeys.autoUpdate, _autoUpdate);+ },+ ),+ SettingsTile.switchTile(+ leading: Icons.extension_rounded,+ title: const Text('规则更新'),+ initialValue: _pluginUpdate,+ onToggle: (value) {+ setState(() => _pluginUpdate = value ?? !_pluginUpdate);+ GStorage.putSetting(+ SettingsKeys.checkPluginUpdateOnStartup,+ _pluginUpdate,+ );+ },+ ),+ ],+ ),+ ],+ ),+ );+}diff --git a/lib/services/storage/image_cache_service.dart b/lib/services/storage/image_cache_service.dartnew file mode 100644index 00000000..2b28c9c7--- /dev/null+++ b/lib/services/storage/image_cache_service.dart@@ -0,0 +1,44 @@+import 'dart:io';++import 'package:flutter/painting.dart';+import 'package:flutter_cache_manager/flutter_cache_manager.dart';+import 'package:path/path.dart' as p;+import 'package:path_provider/path_provider.dart';++class ImageCacheService {+ Stream<File> _files() async* {+ final temporary = await getTemporaryDirectory();+ final directory =+ Directory(p.join(temporary.path, DefaultCacheManager.key));+ if (!await directory.exists()) return;+ yield* directory+ .list(recursive: true, followLinks: false)+ .where((entry) => entry is File)+ .cast<File>();+ }++ Future<int> sizeInBytes() async {+ var bytes = 0;+ await for (final file in _files()) {+ // Files may expire during enumeration.+ final stat = await file.stat();+ if (stat.type == FileSystemEntityType.file) bytes += stat.size;+ }+ return bytes;+ }++ Future<void> clear() async {+ // Include orphaned files, but leave images cached after this snapshot.+ final files = await _files().toList();+ await DefaultCacheManager().emptyCache();+ for (final file in files) {+ try {+ await file.delete();+ } on PathNotFoundException {+ // Already removed by the cache manager.+ }+ }+ PaintingBinding.instance.imageCache.clear();+ PaintingBinding.instance.imageCache.clearLiveImages();+ }+}