Compare commits

..

1 Commits

Author SHA1 Message Date
e8d98e8274 Add support for ArrayBuffer to showInputDialog. 2025-10-28 18:42:59 +08:00
4 changed files with 23 additions and 27 deletions

View File

@@ -1334,7 +1334,7 @@ let UI = {
* Show an input dialog
* @param title {string}
* @param validator {(string) => string | null | undefined} - A function that validates the input. If the function returns a string, the dialog will show the error message.
* @param image {string?} - Available since 1.4.6. An optional image to show in the dialog. You can use this to show a captcha.
* @param image {string | ArrayBuffer | null | undefined} - Since 1.4.6, you can pass an image url to show an image in the dialog. Since 1.5.3, you can also pass an ArrayBuffer to show a custom image.
* @returns {Promise<string | null>} - The input value. If the dialog is canceled, return null.
*/
showInputDialog: (title, validator, image) => {

View File

@@ -1,3 +1,5 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_qjs/flutter_qjs.dart';
import 'package:url_launcher/url_launcher_string.dart';
@@ -40,7 +42,6 @@ mixin class JsUiApi {
var image = message['image'];
if (title is! String) return;
if (validator != null && validator is! JSInvokable) return;
if (image != null && image is! String) return;
return _showInputDialog(title, validator, image);
case 'showSelectDialog':
var title = message['title'];
@@ -126,13 +127,25 @@ mixin class JsUiApi {
controller?.close();
}
Future<String?> _showInputDialog(String title, JSInvokable? validator, String? image) async {
Future<String?> _showInputDialog(String title, JSInvokable? validator, dynamic image) async {
String? result;
var func = validator == null ? null : JSAutoFreeFunction(validator);
String? imageUrl;
Uint8List? imageData;
if (image != null) {
if (image is String) {
imageUrl = image;
} else if (image is Uint8List) {
imageData = image;
} else if (image is List<int>) {
imageData = Uint8List.fromList(image);
}
}
await showInputDialog(
context: App.rootContext,
title: title,
image: image,
image: imageUrl,
imageData: imageData,
onConfirm: (v) {
if (func != null) {
var res = func.call([v]);

View File

@@ -360,6 +360,7 @@ Future<void> showInputDialog({
String cancelText = "Cancel",
RegExp? inputValidator,
String? image,
Uint8List? imageData,
}) {
var controller = TextEditingController(text: initialValue);
bool isLoading = false;
@@ -379,6 +380,11 @@ Future<void> showInputDialog({
height: 108,
child: Image.network(image, fit: BoxFit.none),
).paddingBottom(8),
if (image == null && imageData != null)
SizedBox(
height: 108,
child: Image.memory(imageData, fit: BoxFit.none),
).paddingBottom(8),
TextField(
controller: controller,
decoration: InputDecoration(

View File

@@ -1245,15 +1245,6 @@ class _LoginPageState extends State<_LoginPage> {
if (widget.config.checkLoginStatus != null &&
widget.config.checkLoginStatus!(url, title)) {
var cookies = (await c.getCookies(url)) ?? [];
var localStorageItems = await c.webStorage.localStorage.getItems();
var mappedLocalStorage = <String, dynamic>{};
for (var item in localStorageItems) {
if (item.key != null) {
mappedLocalStorage[item.key!] = item.value;
}
}
widget.source.data['_localStorage'] = mappedLocalStorage;
await widget.source.saveData();
SingleInstanceCookieJar.instance?.saveFromResponse(
Uri.parse(url),
cookies,
@@ -1315,20 +1306,6 @@ class _LoginPageState extends State<_LoginPage> {
Uri.parse(url),
cookies,
);
var localStorageJson = await webview.evaluateJavascript(
"JSON.stringify(window.localStorage);",
);
var localStorage = <String, dynamic>{};
try {
var decoded = jsonDecode(localStorageJson ?? '');
if (decoded is Map<String, dynamic>) {
localStorage = decoded;
}
} catch (e) {
Log.error("ComicSourcePage", "Failed to parse localStorage JSON\n$e");
}
widget.source.data['_localStorage'] = localStorage;
await widget.source.saveData();
success = true;
widget.config.onLoginWithWebviewSuccess?.call();
webview.close();