From 1c1f4180195d66957f4fa57b8a0ed3b9b211a981 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 18 Jan 2025 22:55:34 +0800 Subject: [PATCH] fix UI api --- lib/foundation/js_engine.dart | 3 +++ lib/pages/comic_source_page.dart | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/foundation/js_engine.dart b/lib/foundation/js_engine.dart index 9accea8..fd87135 100644 --- a/lib/foundation/js_engine.dart +++ b/lib/foundation/js_engine.dart @@ -714,6 +714,8 @@ mixin class _JsUiApi { var content = message['content']; var actions = {}; for (var action in message['actions']) { + // [message] will be released after the method call, causing the action to be invalid, so we need to duplicate it + (action['callback'] as JSInvokable).dup(); actions[action['text']] = JSAutoFreeFunction(action['callback']); } showDialog(context: App.rootContext, builder: (context) { @@ -724,6 +726,7 @@ mixin class _JsUiApi { return TextButton( onPressed: () { entry.value.call([]); + context.pop(); }, child: Text(entry.key), ); diff --git a/lib/pages/comic_source_page.dart b/lib/pages/comic_source_page.dart index dd43ef1..e8c43a6 100644 --- a/lib/pages/comic_source_page.dart +++ b/lib/pages/comic_source_page.dart @@ -246,7 +246,7 @@ class _BodyState extends State<_Body> { ), ); } else if (type == "callback") { - yield _CallbackSetting(setting: item); + yield _CallbackSetting(setting: item, sourceKey: source.key); } } catch (e, s) { Log.error("ComicSourcePage", "Failed to build a setting\n$e\n$s"); @@ -682,10 +682,12 @@ class _CheckUpdatesButtonState extends State<_CheckUpdatesButton> { } class _CallbackSetting extends StatefulWidget { - const _CallbackSetting({required this.setting}); + const _CallbackSetting({required this.setting, required this.sourceKey}); final MapEntry> setting; + final String sourceKey; + @override State<_CallbackSetting> createState() => _CallbackSettingState(); } @@ -719,11 +721,11 @@ class _CallbackSettingState extends State<_CallbackSetting> { @override Widget build(BuildContext context) { return ListTile( - title: Text(title.ts(key)), + title: Text(title.ts(widget.sourceKey)), trailing: Button.normal( onPressed: onClick, isLoading: isLoading, - child: Text(buttonText.ts(key)), + child: Text(buttonText.ts(widget.sourceKey)), ).fixHeight(32), ); }