mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-01-11 22:40:36 +00:00
fix webview
This commit is contained in:
parent
9f39be7bb8
commit
da63d64d4d
9 changed files with 100 additions and 110 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import 'dart:io';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -28,11 +27,6 @@ late Isar isar;
|
|||
|
||||
void main(List<String> args) async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
if (Platform.isMacOS) {
|
||||
if (runWebViewTitleBarWidget(args)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
MediaKit.ensureInitialized();
|
||||
await RustLib.init();
|
||||
if (!(Platform.isAndroid || Platform.isIOS)) {
|
||||
|
|
|
|||
|
|
@ -216,6 +216,13 @@ class _CodeEditorState extends ConsumerState<CodeEditor> {
|
|||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
source?.sourceCode = controller.text;
|
||||
});
|
||||
if (source != null && mounted) {
|
||||
isar.writeTxnSync(
|
||||
() => isar.sources.putSync(source!));
|
||||
}
|
||||
setState(() {
|
||||
result = null;
|
||||
_isLoading = true;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
// ignore_for_file: depend_on_referenced_packages
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
|
@ -11,8 +9,6 @@ import 'package:mangayomi/services/http/m_client.dart';
|
|||
import 'package:mangayomi/utils/global_style.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class MangaWebView extends ConsumerStatefulWidget {
|
||||
final String url;
|
||||
|
|
@ -29,59 +25,19 @@ class MangaWebView extends ConsumerStatefulWidget {
|
|||
}
|
||||
|
||||
class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
||||
final GlobalKey webViewKey = GlobalKey();
|
||||
|
||||
double _progress = 0;
|
||||
@override
|
||||
void initState() {
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
||||
_runWebViewDesktop();
|
||||
} else {
|
||||
setState(() {
|
||||
_isNotDesktop = true;
|
||||
});
|
||||
if (Platform.isWindows) {
|
||||
_runWindowWebView();
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
final _windowsWebview = FlutterWindowsWebview();
|
||||
Webview? _desktopWebview;
|
||||
void _runWebViewDesktop() async {
|
||||
if (Platform.isLinux || Platform.isMacOS) {
|
||||
_desktopWebview = await WebviewWindow.create(
|
||||
configuration: CreateConfiguration(
|
||||
userDataFolderWindows: await getWebViewPath(),
|
||||
titleBarTopPadding: Platform.isMacOS ? 20 : 0,
|
||||
),
|
||||
);
|
||||
final timer = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
try {
|
||||
final cookieList = await _desktopWebview!.getCookies(widget.url);
|
||||
for (var c in cookieList) {
|
||||
final cookie =
|
||||
c.entries.map((e) => "${e.key}=${e.value}").join(";");
|
||||
await MClient.setCookie(_url, "", cookie: cookie);
|
||||
}
|
||||
} catch (_) {}
|
||||
});
|
||||
_desktopWebview!
|
||||
..launch(widget.url)
|
||||
..addOnWebMessageReceivedCallback((s) {
|
||||
if (s.substring(0, 2) == "UA") {
|
||||
MClient.setCookie(_url, s.replaceFirst("UA", ""));
|
||||
}
|
||||
})
|
||||
..addScriptToExecuteOnDocumentCreated(
|
||||
"window.chrome.webview.postMessage(\"UA\" + navigator.userAgent)")
|
||||
..onClose.whenComplete(() async {
|
||||
timer.cancel();
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
void _runWindowWebView() async {
|
||||
//credit: https://github.com/wgh136/PicaComic/blob/master/lib/network/nhentai_network/cloudflare.dart
|
||||
else if (Platform.isWindows && await FlutterWindowsWebview.isAvailable()) {
|
||||
if (await FlutterWindowsWebview.isAvailable()) {
|
||||
_windowsWebview.launchWebview(
|
||||
widget.url,
|
||||
WebviewOptions(messageReceiver: (s) {
|
||||
|
|
@ -100,7 +56,6 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
}
|
||||
}
|
||||
|
||||
bool _isNotDesktop = false;
|
||||
InAppWebViewController? _webViewController;
|
||||
late String _url = widget.url;
|
||||
late String _title = widget.title;
|
||||
|
|
@ -109,7 +64,7 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = l10nLocalizations(context);
|
||||
return !_isNotDesktop
|
||||
return Platform.isWindows
|
||||
? Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
|
|
@ -120,9 +75,6 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
),
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
if (Platform.isLinux || Platform.isMacOS) {
|
||||
_desktopWebview!.close();
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: const Icon(Icons.close)),
|
||||
|
|
@ -203,7 +155,7 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
Share.share(_url);
|
||||
} else if (value == 2) {
|
||||
await InAppBrowser.openWithSystemBrowser(
|
||||
url: Uri.parse(_url));
|
||||
url: WebUri(_url));
|
||||
} else if (value == 3) {
|
||||
CookieManager.instance().deleteAllCookies();
|
||||
MClient.deleteAllCookies(_url);
|
||||
|
|
@ -217,7 +169,6 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
: Container(),
|
||||
Expanded(
|
||||
child: InAppWebView(
|
||||
key: webViewKey,
|
||||
onWebViewCreated: (controller) async {
|
||||
_webViewController = controller;
|
||||
},
|
||||
|
|
@ -283,8 +234,7 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
});
|
||||
}
|
||||
},
|
||||
initialUrlRequest:
|
||||
URLRequest(url: Uri.parse(widget.url)),
|
||||
initialUrlRequest: URLRequest(url: WebUri(widget.url)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
@ -294,11 +244,3 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getWebViewPath() async {
|
||||
final document = await getApplicationDocumentsDirectory();
|
||||
return p.join(
|
||||
document.path,
|
||||
'desktop_webview_window',
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class MClient {
|
|||
|
||||
static Future<void> setCookie(String url, String ua, {String? cookie}) async {
|
||||
List<String> cookies = [];
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
||||
if (Platform.isWindows) {
|
||||
cookies = cookie
|
||||
?.split(RegExp('(?<=)(,)(?=[^;]+?=)'))
|
||||
.where((cookie) => cookie.isNotEmpty)
|
||||
|
|
@ -71,7 +71,7 @@ class MClient {
|
|||
[];
|
||||
} else {
|
||||
cookies = (await flutter_inappwebview.CookieManager.instance()
|
||||
.getCookies(url: Uri.parse(url)))
|
||||
.getCookies(url: flutter_inappwebview.WebUri(url)))
|
||||
.map((e) => "${e.name}=${e.value}")
|
||||
.toList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import desktop_webview_window
|
||||
import flutter_inappwebview_macos
|
||||
import flutter_qjs
|
||||
import flutter_web_auth_2
|
||||
import isar_flutter_libs
|
||||
|
|
@ -22,7 +22,7 @@ import window_manager
|
|||
import window_to_front
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
DesktopWebviewWindowPlugin.register(with: registry.registrar(forPlugin: "DesktopWebviewWindowPlugin"))
|
||||
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
|
||||
FlutterQjsPlugin.register(with: registry.registrar(forPlugin: "FlutterQjsPlugin"))
|
||||
FlutterWebAuth2Plugin.register(with: registry.registrar(forPlugin: "FlutterWebAuth2Plugin"))
|
||||
IsarFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "IsarFlutterLibsPlugin"))
|
||||
|
|
|
|||
105
pubspec.lock
105
pubspec.lock
|
|
@ -58,10 +58,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: asn1lib
|
||||
sha256: "6b151826fcc95ff246cd219a0bf4c753ea14f4081ad71c61939becf3aba27f70"
|
||||
sha256: bf1a19d6ebea1b3b6151304936955d7d73e1f00b75e544c01a60fb2e832ffe1d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.5.5"
|
||||
version: "1.5.6"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -138,10 +138,10 @@ packages:
|
|||
dependency: "direct dev"
|
||||
description:
|
||||
name: build_runner
|
||||
sha256: dd09dd4e2b078992f42aac7f1a622f01882a8492fef08486b27ddde929c19f04
|
||||
sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.12"
|
||||
version: "2.4.13"
|
||||
build_runner_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -302,15 +302,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.10"
|
||||
desktop_webview_window:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: "861cb573a6decb815741ed76e845fe05a3662c95"
|
||||
url: "https://github.com/kodjodevf/desktop_webview_window.git"
|
||||
source: git
|
||||
version: "0.2.3"
|
||||
directed_graph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -419,10 +410,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: "825aec673606875c33cd8d3c4083f1a3c3999015a84178b317b7ef396b7384f3"
|
||||
sha256: "167bb619cdddaa10ef2907609feb8a79c16dfa479d3afaf960f8e223f754bf12"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.0.7"
|
||||
version: "8.1.2"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -472,10 +463,66 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_inappwebview
|
||||
sha256: d198297060d116b94048301ee6749cd2e7d03c1f2689783f52d210a6b7aba350
|
||||
sha256: "274edbb07196944e316722d9f6f641c77d0e71261200869887e10f59614c0458"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.8.0"
|
||||
version: "6.1.3"
|
||||
flutter_inappwebview_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_android
|
||||
sha256: f48203a11c5eb0c23dd5a3cb3638ae678056b6ceae22819373e36c6cb4f1d46a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter_inappwebview_internal_annotations:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_internal_annotations
|
||||
sha256: "5f80fd30e208ddded7dbbcd0d569e7995f9f63d45ea3f548d8dd4c0b473fb4c8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter_inappwebview_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_ios
|
||||
sha256: f6f88d464b38f2fc1c5f2ae74024498115eb1470715bd8b40f902dd4ac99ccc8
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter_inappwebview_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_macos
|
||||
sha256: "68e0c3785d8d789710cda7d7efe6effa337c91bf300dd28af7efc2d358fa1a98"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter_inappwebview_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_platform_interface
|
||||
sha256: "97b4ab116d949ede20c90c7e3d15d24afaf1b706cc0af96b060770293cd6c49d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
flutter_inappwebview_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_web
|
||||
sha256: f7f97b6faa39416e4e86da1184edd4de6c27b271d036f0838ea3ff9a250a1de2
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter_inappwebview_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_windows
|
||||
sha256: "86702d2109384311f8ea634855e90ee143b9bfabddd3858696d905a2c28808aa"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.0"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
@ -1347,18 +1394,18 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: share_plus
|
||||
sha256: ef3489a969683c4f3d0239010cc8b7a2a46543a8d139e111c06c558875083544
|
||||
sha256: "468c43f285207c84bcabf5737f33b914ceb8eb38398b91e5e3ad1698d1b72a52"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "9.0.0"
|
||||
version: "10.0.2"
|
||||
share_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: share_plus_platform_interface
|
||||
sha256: "0f9e4418835d1b2c3ae78fdb918251959106cefdbc4dd43526e182f80e82f6d4"
|
||||
sha256: "6ababf341050edff57da8b6990f11f4e99eaba837865e2e6defe16d039619db5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
version: "5.0.0"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1456,10 +1503,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: synchronized
|
||||
sha256: "51b08572b9f091f8c3eb4d9d4be253f196ff0075d5ec9b10a884026d5b55d7bc"
|
||||
sha256: "69fe30f3a8b04a0be0c15ae6490fc859a78ef4c43ae2dd5e8a623d45bfcf9225"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.3.0+2"
|
||||
version: "3.3.0+3"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1592,10 +1639,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: uuid
|
||||
sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77
|
||||
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.5.0"
|
||||
version: "4.5.1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1648,10 +1695,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
|
||||
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
version: "1.1.0"
|
||||
web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1728,10 +1775,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: xxh3
|
||||
sha256: a92b30944a9aeb4e3d4f3c3d4ddb3c7816ca73475cd603682c4f8149690f56d7
|
||||
sha256: cbeb0e1d10f4c6bf67b650f395eac0cc689425b5efc2ba0cc3d3e069a0beaeec
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "1.1.0"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -26,16 +26,12 @@ dependencies:
|
|||
url_launcher: ^6.3.0
|
||||
package_info_plus: ^8.0.0
|
||||
permission_handler: ^11.3.1
|
||||
flutter_inappwebview: ^5.8.0
|
||||
flutter_inappwebview: ^6.1.3
|
||||
draggable_menu: ^4.4.1
|
||||
isar: 3.1.0+1
|
||||
isar_flutter_libs: 3.1.0+1
|
||||
share_plus: ^9.0.0
|
||||
share_plus: ^10.0.2
|
||||
xpath_selector_html_parser: ^3.0.1
|
||||
desktop_webview_window:
|
||||
git:
|
||||
url: https://github.com/kodjodevf/desktop_webview_window.git
|
||||
ref: main
|
||||
archive: ^3.6.1
|
||||
file_picker: ^8.0.5
|
||||
path_provider: ^2.1.3
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
|
||||
#include <flutter_qjs/flutter_qjs_plugin.h>
|
||||
#include <flutter_windows_webview/flutter_windows_webview_plugin_c_api.h>
|
||||
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
|
||||
|
|
@ -20,6 +21,8 @@
|
|||
#include <window_to_front/window_to_front_plugin.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
|
||||
FlutterQjsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterQjsPlugin"));
|
||||
FlutterWindowsWebviewPluginCApiRegisterWithRegistrar(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
flutter_inappwebview_windows
|
||||
flutter_qjs
|
||||
flutter_windows_webview
|
||||
isar_flutter_libs
|
||||
|
|
|
|||
Loading…
Reference in a new issue