mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-03-11 17:25:32 +00:00
Upgrade flutter_inappwebview
This commit is contained in:
parent
16d6979688
commit
3422076fa5
10 changed files with 223 additions and 73 deletions
|
|
@ -183,7 +183,7 @@ class MBridge {
|
|||
headlessWebView!.dispose();
|
||||
},
|
||||
initialUrlRequest: URLRequest(
|
||||
url: Uri.parse(url),
|
||||
url: WebUri(url),
|
||||
),
|
||||
);
|
||||
headlessWebView.run();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ Future<int> start(String mcfg) async {
|
|||
|
||||
const String _libName = 'libmtorrentserver';
|
||||
|
||||
/// The dynamic library in which the symbols for [NativeAddBindings] can be found.
|
||||
final DynamicLibrary _dylib = () {
|
||||
if (Platform.isMacOS) {
|
||||
return DynamicLibrary.open('$_libName.dylib');
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ void main(List<String> args) async {
|
|||
// Override the default HTTP client.
|
||||
HttpOverrides.global = MyHttpoverrides();
|
||||
// If running on desktop platforms and web view title bar widget is active, exit.
|
||||
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
|
||||
if (Platform.isLinux || Platform.isWindows) {
|
||||
if (runWebViewTitleBarWidget(args)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -992,56 +992,65 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
}
|
||||
|
||||
Widget _topButtonBar(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
BackButton(
|
||||
color: Colors.white,
|
||||
onPressed: () async {
|
||||
if (_isDesktop) {
|
||||
final isFullScreen = await windowManager.isFullScreen();
|
||||
if (isFullScreen) {
|
||||
setFullScreen(value: false);
|
||||
} else {
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
||||
overlays: SystemUiOverlay.values);
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
title: SizedBox(
|
||||
width: context.mediaWidth(0.8),
|
||||
child: Text(
|
||||
widget.episode.manga.value!.name!,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, color: Colors.white),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: _enterFullScreen,
|
||||
builder: (context, fullScreen, _) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: !_isDesktop && !fullScreen
|
||||
? MediaQuery.of(context).padding.top
|
||||
: 0),
|
||||
child: Row(
|
||||
children: [
|
||||
BackButton(
|
||||
color: Colors.white,
|
||||
onPressed: () async {
|
||||
if (_isDesktop) {
|
||||
if (fullScreen) {
|
||||
setFullScreen(value: false);
|
||||
} else {
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
||||
overlays: SystemUiOverlay.values);
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
title: SizedBox(
|
||||
width: context.mediaWidth(0.8),
|
||||
child: Text(
|
||||
widget.episode.manga.value!.name!,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, color: Colors.white),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
subtitle: SizedBox(
|
||||
width: context.mediaWidth(0.8),
|
||||
child: Text(
|
||||
widget.episode.name!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.white.withOpacity(0.7)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: SizedBox(
|
||||
width: context.mediaWidth(0.8),
|
||||
child: Text(
|
||||
widget.episode.name!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.white.withOpacity(0.7)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _resize(BoxFit fit) async {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
|
@ -30,10 +31,11 @@ class MangaWebView extends ConsumerStatefulWidget {
|
|||
|
||||
class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
||||
final GlobalKey webViewKey = GlobalKey();
|
||||
|
||||
late final MyInAppBrowser browser;
|
||||
double progress = 0;
|
||||
@override
|
||||
void initState() {
|
||||
browser = MyInAppBrowser(context: context);
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
||||
_runWebViewDesktop();
|
||||
} else {
|
||||
|
|
@ -46,17 +48,33 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
|
||||
Webview? webview;
|
||||
_runWebViewDesktop() async {
|
||||
webview = await WebviewWindow.create(
|
||||
configuration: CreateConfiguration(
|
||||
userDataFolderWindows: await getWebViewPath(),
|
||||
),
|
||||
);
|
||||
webview!
|
||||
..setBrightness(Brightness.dark)
|
||||
..launch(widget.url)
|
||||
..onClose.whenComplete(() {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
if (Platform.isMacOS) {
|
||||
await browser.openUrlRequest(
|
||||
urlRequest: URLRequest(url: WebUri(widget.url)),
|
||||
settings: InAppBrowserClassSettings(
|
||||
browserSettings: InAppBrowserSettings(
|
||||
toolbarTopBackgroundColor: Colors.blue,
|
||||
presentationStyle: ModalPresentationStyle.POPOVER),
|
||||
webViewSettings: InAppWebViewSettings(
|
||||
isInspectable: kDebugMode,
|
||||
useShouldOverrideUrlLoading: true,
|
||||
useOnLoadResource: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
webview = await WebviewWindow.create(
|
||||
configuration: CreateConfiguration(
|
||||
userDataFolderWindows: await getWebViewPath(),
|
||||
),
|
||||
);
|
||||
webview!
|
||||
..setBrightness(Brightness.dark)
|
||||
..launch(widget.url)
|
||||
..onClose.whenComplete(() {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool isNotDesktop = false;
|
||||
|
|
@ -79,7 +97,14 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
),
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
webview!.close();
|
||||
if (Platform.isMacOS) {
|
||||
if (browser.isOpened()) {
|
||||
browser.close();
|
||||
}
|
||||
} else {
|
||||
webview!.close();
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: const Icon(Icons.close)),
|
||||
|
|
@ -155,7 +180,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();
|
||||
}
|
||||
|
|
@ -228,7 +253,7 @@ class _MangaWebViewState extends ConsumerState<MangaWebView> {
|
|||
_canGoForward = canGoForward;
|
||||
});
|
||||
},
|
||||
initialUrlRequest: URLRequest(url: Uri.parse(widget.url)),
|
||||
initialUrlRequest: URLRequest(url: WebUri(widget.url)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
@ -267,3 +292,70 @@ Future<String?> decodeHtml(Webview webview, {String? sourceId}) async {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class MyInAppBrowser extends InAppBrowser {
|
||||
MyInAppBrowser(
|
||||
{super.windowId,
|
||||
super.initialUserScripts,
|
||||
super.pullToRefreshController,
|
||||
required this.context});
|
||||
late BuildContext context;
|
||||
@override
|
||||
Future onBrowserCreated() async {
|
||||
print("\n\nBrowser Created!\n\n");
|
||||
}
|
||||
|
||||
@override
|
||||
Future onLoadStart(url) async {}
|
||||
|
||||
@override
|
||||
Future onLoadStop(url) async {}
|
||||
|
||||
@override
|
||||
Future<PermissionResponse> onPermissionRequest(request) async {
|
||||
return PermissionResponse(
|
||||
resources: request.resources, action: PermissionResponseAction.GRANT);
|
||||
}
|
||||
|
||||
@override
|
||||
void onLoadError(url, code, message) {
|
||||
pullToRefreshController?.endRefreshing();
|
||||
}
|
||||
|
||||
@override
|
||||
void onProgressChanged(progress) {
|
||||
if (progress == 100) {
|
||||
pullToRefreshController?.endRefreshing();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onExit() {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<NavigationActionPolicy> shouldOverrideUrlLoading(
|
||||
navigationAction) async {
|
||||
var uri = navigationAction.request.url!;
|
||||
|
||||
if (!["http", "https", "file", "chrome", "data", "javascript", "about"]
|
||||
.contains(uri.scheme)) {
|
||||
if (await canLaunchUrl(uri)) {
|
||||
// Launch the App
|
||||
await launchUrl(
|
||||
uri,
|
||||
);
|
||||
// and cancel the request
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
return NavigationActionPolicy.ALLOW;
|
||||
}
|
||||
|
||||
@override
|
||||
void onMainWindowWillClose() {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ Future<String> cloudflareBypass(
|
|||
String ua = "";
|
||||
bool isOk = false;
|
||||
String? html;
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
||||
if (Platform.isWindows || Platform.isLinux) {
|
||||
final webview = await WebviewWindow.create(
|
||||
configuration: CreateConfiguration(
|
||||
windowHeight: 500,
|
||||
|
|
@ -56,7 +56,7 @@ Future<String> cloudflareBypass(
|
|||
isOk = true;
|
||||
headlessWebView!.dispose();
|
||||
},
|
||||
initialUrlRequest: URLRequest(url: Uri.parse(url)),
|
||||
initialUrlRequest: URLRequest(url: WebUri(url)),
|
||||
);
|
||||
|
||||
headlessWebView.run();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ Future<void> addCookie(String sourceId, String url, String ua) async {
|
|||
flutter_inappwebview.CookieManager.instance();
|
||||
|
||||
final cookie = (await cookieManager.getCookie(
|
||||
url: Uri.parse(url), name: "cf_clearance"));
|
||||
url: flutter_inappwebview.WebUri(url), name: "cf_clearance"));
|
||||
if (cookie != null) {
|
||||
final newCookie = "${cookie.name}=${cookie.value}";
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import FlutterMacOS
|
|||
import Foundation
|
||||
|
||||
import desktop_webview_window
|
||||
import flutter_inappwebview_macos
|
||||
import flutter_web_auth_2
|
||||
import isar_flutter_libs
|
||||
import media_kit_libs_macos_video
|
||||
|
|
@ -23,6 +24,7 @@ import window_to_front
|
|||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
DesktopWebviewWindowPlugin.register(with: registry.registrar(forPlugin: "DesktopWebviewWindowPlugin"))
|
||||
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
|
||||
FlutterWebAuth2Plugin.register(with: registry.registrar(forPlugin: "FlutterWebAuth2Plugin"))
|
||||
IsarFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "IsarFlutterLibsPlugin"))
|
||||
MediaKitLibsMacosVideoPlugin.register(with: registry.registrar(forPlugin: "MediaKitLibsMacosVideoPlugin"))
|
||||
|
|
|
|||
52
pubspec.lock
52
pubspec.lock
|
|
@ -475,10 +475,58 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_inappwebview
|
||||
sha256: d198297060d116b94048301ee6749cd2e7d03c1f2689783f52d210a6b7aba350
|
||||
sha256: "3e9a443a18ecef966fb930c3a76ca5ab6a7aafc0c7b5e14a4a850cf107b09959"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.8.0"
|
||||
version: "6.0.0"
|
||||
flutter_inappwebview_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_android
|
||||
sha256: fd4db51e46f49b140d83a3206851432c54ea920b381137c0ba82d0cf59be1dee
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.12"
|
||||
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: f363577208b97b10b319cd0c428555cd8493e88b468019a8c5635a0e4312bd0f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.13"
|
||||
flutter_inappwebview_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_macos
|
||||
sha256: b55b9e506c549ce88e26580351d2c71d54f4825901666bd6cfa4be9415bb2636
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.11"
|
||||
flutter_inappwebview_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_platform_interface
|
||||
sha256: "545fd4c25a07d2775f7d5af05a979b2cac4fbf79393b0a7f5d33ba39ba4f6187"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.10"
|
||||
flutter_inappwebview_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_web
|
||||
sha256: d8c680abfb6fec71609a700199635d38a744df0febd5544c5a020bd73de8ee07
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.8"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ dependencies:
|
|||
url: https://github.com/kodjodevf/background_downloader.git
|
||||
ref: 2cc16eeb475788ec0443b64badc325c00d7dab90
|
||||
permission_handler: ^11.1.0
|
||||
flutter_inappwebview: ^5.7.2+3
|
||||
flutter_inappwebview: ^6.0.0
|
||||
draggable_menu: ^4.4.1
|
||||
isar: 3.1.0+1
|
||||
isar_flutter_libs: 3.1.0+1
|
||||
|
|
|
|||
Loading…
Reference in a new issue