Add callback setting

This commit is contained in:
2025-01-18 16:07:16 +08:00
parent 16512f2711
commit d9084272e5
4 changed files with 91 additions and 4 deletions

View File

@@ -165,7 +165,7 @@ class JsEngine with _JSEngineApi {
String settingKey = message["setting_key"];
var source = ComicSource.find(key)!;
return source.data["settings"]?[settingKey] ??
source.settings?[settingKey]['default'] ??
source.settings?[settingKey]!['default'] ??
(throw "Setting not found: $settingKey");
}
case "isLogged":
@@ -688,3 +688,20 @@ class DocumentWrapper {
return elements.length - 1;
}
}
class JSAutoFreeFunction {
final JSInvokable func;
/// Automatically free the function when it's not used anymore
JSAutoFreeFunction(this.func) {
finalizer.attach(this, func);
}
dynamic call(List<dynamic> args) {
return func(args);
}
static final finalizer = Finalizer<JSInvokable>((func) {
func.free();
});
}