mirror of
https://github.com/venera-app/venera.git
synced 2025-12-16 07:01:16 +00:00
Compare commits
1 Commits
feat/login
...
feat/js-di
| Author | SHA1 | Date | |
|---|---|---|---|
| e8d98e8274 |
@@ -1334,7 +1334,7 @@ let UI = {
|
|||||||
* Show an input dialog
|
* Show an input dialog
|
||||||
* @param title {string}
|
* @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 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.
|
* @returns {Promise<string | null>} - The input value. If the dialog is canceled, return null.
|
||||||
*/
|
*/
|
||||||
showInputDialog: (title, validator, image) => {
|
showInputDialog: (title, validator, image) => {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_qjs/flutter_qjs.dart';
|
import 'package:flutter_qjs/flutter_qjs.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
@@ -40,7 +42,6 @@ mixin class JsUiApi {
|
|||||||
var image = message['image'];
|
var image = message['image'];
|
||||||
if (title is! String) return;
|
if (title is! String) return;
|
||||||
if (validator != null && validator is! JSInvokable) return;
|
if (validator != null && validator is! JSInvokable) return;
|
||||||
if (image != null && image is! String) return;
|
|
||||||
return _showInputDialog(title, validator, image);
|
return _showInputDialog(title, validator, image);
|
||||||
case 'showSelectDialog':
|
case 'showSelectDialog':
|
||||||
var title = message['title'];
|
var title = message['title'];
|
||||||
@@ -126,13 +127,25 @@ mixin class JsUiApi {
|
|||||||
controller?.close();
|
controller?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> _showInputDialog(String title, JSInvokable? validator, String? image) async {
|
Future<String?> _showInputDialog(String title, JSInvokable? validator, dynamic image) async {
|
||||||
String? result;
|
String? result;
|
||||||
var func = validator == null ? null : JSAutoFreeFunction(validator);
|
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(
|
await showInputDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
title: title,
|
title: title,
|
||||||
image: image,
|
image: imageUrl,
|
||||||
|
imageData: imageData,
|
||||||
onConfirm: (v) {
|
onConfirm: (v) {
|
||||||
if (func != null) {
|
if (func != null) {
|
||||||
var res = func.call([v]);
|
var res = func.call([v]);
|
||||||
|
|||||||
@@ -360,6 +360,7 @@ Future<void> showInputDialog({
|
|||||||
String cancelText = "Cancel",
|
String cancelText = "Cancel",
|
||||||
RegExp? inputValidator,
|
RegExp? inputValidator,
|
||||||
String? image,
|
String? image,
|
||||||
|
Uint8List? imageData,
|
||||||
}) {
|
}) {
|
||||||
var controller = TextEditingController(text: initialValue);
|
var controller = TextEditingController(text: initialValue);
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
@@ -379,6 +380,11 @@ Future<void> showInputDialog({
|
|||||||
height: 108,
|
height: 108,
|
||||||
child: Image.network(image, fit: BoxFit.none),
|
child: Image.network(image, fit: BoxFit.none),
|
||||||
).paddingBottom(8),
|
).paddingBottom(8),
|
||||||
|
if (image == null && imageData != null)
|
||||||
|
SizedBox(
|
||||||
|
height: 108,
|
||||||
|
child: Image.memory(imageData, fit: BoxFit.none),
|
||||||
|
).paddingBottom(8),
|
||||||
TextField(
|
TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
|||||||
@@ -1245,15 +1245,6 @@ class _LoginPageState extends State<_LoginPage> {
|
|||||||
if (widget.config.checkLoginStatus != null &&
|
if (widget.config.checkLoginStatus != null &&
|
||||||
widget.config.checkLoginStatus!(url, title)) {
|
widget.config.checkLoginStatus!(url, title)) {
|
||||||
var cookies = (await c.getCookies(url)) ?? [];
|
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(
|
SingleInstanceCookieJar.instance?.saveFromResponse(
|
||||||
Uri.parse(url),
|
Uri.parse(url),
|
||||||
cookies,
|
cookies,
|
||||||
@@ -1315,20 +1306,6 @@ class _LoginPageState extends State<_LoginPage> {
|
|||||||
Uri.parse(url),
|
Uri.parse(url),
|
||||||
cookies,
|
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;
|
success = true;
|
||||||
widget.config.onLoginWithWebviewSuccess?.call();
|
widget.config.onLoginWithWebviewSuccess?.call();
|
||||||
webview.close();
|
webview.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user