fix UI api

This commit is contained in:
2025-01-18 22:55:34 +08:00
parent b6e5035509
commit 1c1f418019
2 changed files with 9 additions and 4 deletions

View File

@@ -714,6 +714,8 @@ mixin class _JsUiApi {
var content = message['content']; var content = message['content'];
var actions = <String, JSAutoFreeFunction>{}; var actions = <String, JSAutoFreeFunction>{};
for (var action in message['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']); actions[action['text']] = JSAutoFreeFunction(action['callback']);
} }
showDialog(context: App.rootContext, builder: (context) { showDialog(context: App.rootContext, builder: (context) {
@@ -724,6 +726,7 @@ mixin class _JsUiApi {
return TextButton( return TextButton(
onPressed: () { onPressed: () {
entry.value.call([]); entry.value.call([]);
context.pop();
}, },
child: Text(entry.key), child: Text(entry.key),
); );

View File

@@ -246,7 +246,7 @@ class _BodyState extends State<_Body> {
), ),
); );
} else if (type == "callback") { } else if (type == "callback") {
yield _CallbackSetting(setting: item); yield _CallbackSetting(setting: item, sourceKey: source.key);
} }
} catch (e, s) { } catch (e, s) {
Log.error("ComicSourcePage", "Failed to build a setting\n$e\n$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 { class _CallbackSetting extends StatefulWidget {
const _CallbackSetting({required this.setting}); const _CallbackSetting({required this.setting, required this.sourceKey});
final MapEntry<String, Map<String, dynamic>> setting; final MapEntry<String, Map<String, dynamic>> setting;
final String sourceKey;
@override @override
State<_CallbackSetting> createState() => _CallbackSettingState(); State<_CallbackSetting> createState() => _CallbackSettingState();
} }
@@ -719,11 +721,11 @@ class _CallbackSettingState extends State<_CallbackSetting> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListTile( return ListTile(
title: Text(title.ts(key)), title: Text(title.ts(widget.sourceKey)),
trailing: Button.normal( trailing: Button.normal(
onPressed: onClick, onPressed: onClick,
isLoading: isLoading, isLoading: isLoading,
child: Text(buttonText.ts(key)), child: Text(buttonText.ts(widget.sourceKey)),
).fixHeight(32), ).fixHeight(32),
); );
} }