From ba481d440cc8eb500393b437fa9c25743de10664 Mon Sep 17 00:00:00 2001 From: MuZhou233 Date: Wed, 25 Sep 2024 18:05:31 +0800 Subject: [PATCH] feat: add `tuihub-rss` special support --- .../settings/porter/porter_manage_page.dart | 12 ++-- .../yesod/manage_notify_target_page.dart | 25 +++++++ lib/view/specialized/right_panel_form.dart | 69 +++++++++++++++++-- pubspec.yaml | 2 +- 4 files changed, 95 insertions(+), 13 deletions(-) diff --git a/lib/view/pages/settings/porter/porter_manage_page.dart b/lib/view/pages/settings/porter/porter_manage_page.dart index 055b417..721a118 100644 --- a/lib/view/pages/settings/porter/porter_manage_page.dart +++ b/lib/view/pages/settings/porter/porter_manage_page.dart @@ -178,19 +178,15 @@ class PorterEditPanel extends StatelessWidget { labelText: '全局名称', ), ), - TextFormField( - initialValue: porter.featureSummary.toString(), - readOnly: true, - decoration: const InputDecoration( - border: OutlineInputBorder(), - label: Text('支持功能'), - ), - ), SwitchFormField( initialValue: enabled, onSaved: (newValue) => enabled = newValue!, title: const Text('启用'), ), + TextFormMessage( + title: '支持功能', + message: porter.featureSummary.toString(), + ), ], errorMsg: state is TipherethEditPorterState && state.failed ? state.msg diff --git a/lib/view/pages/yesod/manage_notify_target_page.dart b/lib/view/pages/yesod/manage_notify_target_page.dart index 35cd441..2c68968 100644 --- a/lib/view/pages/yesod/manage_notify_target_page.dart +++ b/lib/view/pages/yesod/manage_notify_target_page.dart @@ -162,6 +162,26 @@ class NotifyTargetEditPanel extends StatelessWidget { FramePage.of(context)?.closeDrawer(); } + List specSectionTuiHubRSS(NotifyTarget target, FeatureFlag flag) { + debugPrint('specSectionTuiHubRSS ${flag.id}'); + if (flag.id != 'rss') { + return []; + } + var url = '未知'; + if (flag.extra['URLPrefix'] != null) { + url = '${flag.extra['URLPrefix']}/${target.id.id}'; + } + return [ + const FormSectionDivider( + title: 'TuiHub RSS', + ), + TextReadOnlyFormField( + label: '订阅链接', + value: url, + ) + ]; + } + @override Widget build(BuildContext context) { final notifyDestinations = context @@ -234,6 +254,11 @@ class NotifyTargetEditPanel extends StatelessWidget { onSaved: (newValue) => enabled = newValue!, title: const Text('启用'), ), + ...specSectionTuiHubRSS( + target, + notifyDestinations.firstWhere( + (element) => element.id == destination.id, + orElse: FeatureFlag.new)), ], errorMsg: state is NetzachTargetEditState && state.failed ? state.msg diff --git a/lib/view/specialized/right_panel_form.dart b/lib/view/specialized/right_panel_form.dart index 293b2bb..edb38fe 100644 --- a/lib/view/specialized/right_panel_form.dart +++ b/lib/view/specialized/right_panel_form.dart @@ -137,6 +137,65 @@ class _RightPanelFormState extends State { } } +class FormSectionDivider extends StatelessWidget { + const FormSectionDivider({ + super.key, + required this.title, + }); + + final String title; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + Divider( + height: 10, + indent: 10, + endIndent: 10, + thickness: 2, + color: Theme.of(context).brightness == Brightness.dark + ? Theme.of(context).colorScheme.outline + : Theme.of(context).colorScheme.outlineVariant, + ), + Text( + title, + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ); + } +} + +class TextFormMessage extends StatelessWidget { + const TextFormMessage({ + super.key, + required this.title, + this.message, + }); + + final String title; + final String? message; + + @override + Widget build(BuildContext context) { + return ExpansionTile( + title: Text( + title, + ), + children: [ + if (message != null) + Container( + padding: const EdgeInsets.all(16), + child: Text( + message!, + ), + ) + ], + ); + } +} + class TextFormErrorMessage extends StatelessWidget { const TextFormErrorMessage({ super.key, @@ -242,7 +301,7 @@ class _FeatureRequestFormFieldState extends State { selectedFlag = widget.initialValue != null ? featureFlags.firstWhere( (e) => e.id == widget.initialValue!.id, - orElse: () => featureFlags.first, + orElse: FeatureFlag.new, ) : featureFlags.first; config = widget.initialValue?.configJson ?? config; @@ -274,8 +333,9 @@ class _FeatureRequestFormFieldState extends State { children: [ if (featureFlags.isEmpty) const TextFormErrorMessage(message: '服务器无可用类型') - else if (!featureFlags.any((e) => e.requireContext)) - TextFormErrorMessage(message: '服务器未启用${selectedFlag?.id ?? ''}'), + else if (!featureFlags.any((e) => e.id == selectedFlag?.id)) + TextFormErrorMessage( + message: '服务器未启用 ${widget.initialValue?.id ?? '功能'}'), if (widget.flagReadOnly) TextReadOnlyFormField( label: '类型', @@ -376,7 +436,8 @@ class _FeatureRequestFormFieldState extends State { return null; }, ), - if (selectedFlag != null) + if (selectedFlag != null && + featureFlags.any((e) => e.id == selectedFlag!.id)) JsonForm( key: ValueKey(buildCounter++), controller: jsonFormController, diff --git a/pubspec.yaml b/pubspec.yaml index d6fa3fe..4d05956 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,7 +59,7 @@ dependencies: tuihub_protos: git: url: https://github.com/tuihub/protos.git - ref: v0.4.22 + ref: v0.4.23 fixnum: ^1.1.0 # theme