From 51c2bf0d6f29aad10bbe954da850360a2b2e4e0f Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 11 Feb 2025 20:08:02 +0800 Subject: [PATCH] [windows] Replace desktop_webview_window with flutter_inappwebview --- lib/network/cloudflare.dart | 2 +- lib/pages/comic_source_page.dart | 4 +- lib/pages/webview.dart | 43 ++++++++++-------- pubspec.lock | 77 +++++++++++++++++--------------- pubspec.yaml | 6 ++- 5 files changed, 74 insertions(+), 58 deletions(-) diff --git a/lib/network/cloudflare.dart b/lib/network/cloudflare.dart index 810bafa..4c078e2 100644 --- a/lib/network/cloudflare.dart +++ b/lib/network/cloudflare.dart @@ -118,7 +118,7 @@ void passCloudflare(CloudflareException e, void Function() onFinished) async { // windows version of package `flutter_inappwebview` cannot get some cookies // Using DesktopWebview instead - if (App.isLinux || App.isWindows) { + if (App.isLinux) { var webview = DesktopWebview( initialUrl: url, onTitleChange: (title, controller) async { diff --git a/lib/pages/comic_source_page.dart b/lib/pages/comic_source_page.dart index 55298d0..fed0d8a 100644 --- a/lib/pages/comic_source_page.dart +++ b/lib/pages/comic_source_page.dart @@ -1011,7 +1011,7 @@ class _LoginPageState extends State<_LoginPage> { if (widget.config.loginWebsite != null) TextButton( onPressed: () { - if (App.isWindows || App.isLinux) { + if (App.isLinux) { loginWithWebview2(); } else { loginWithWebview(); @@ -1127,7 +1127,7 @@ class _LoginPageState extends State<_LoginPage> { } } - // for windows and linux + // for linux void loginWithWebview2() async { if (!await DesktopWebview.isAvailable()) { context.showMessage(message: "Webview is not available".tl); diff --git a/lib/pages/webview.dart b/lib/pages/webview.dart index 70655f6..88590e2 100644 --- a/lib/pages/webview.dart +++ b/lib/pages/webview.dart @@ -25,8 +25,13 @@ extension WebviewExtension on InAppWebViewController { if (url[url.length - 1] == '/') { url = url.substring(0, url.length - 1); } - CookieManager cookieManager = CookieManager.instance(); - final cookies = await cookieManager.getCookies(url: WebUri(url)); + CookieManager cookieManager = CookieManager.instance( + webViewEnvironment: AppWebview.webViewEnvironment, + ); + final cookies = await cookieManager.getCookies( + url: WebUri(url), + webViewController: this, + ); var res = []; for (var cookie in cookies) { var c = io.Cookie(cookie.name, cookie.value); @@ -90,7 +95,8 @@ class _AppWebviewState extends State { var proxy = appdata.settings['proxy'].toString(); if (proxy != "system" && proxy != "direct") { var proxyAvailable = await WebViewFeature.isFeatureSupported( - WebViewFeature.PROXY_OVERRIDE); + WebViewFeature.PROXY_OVERRIDE, + ); if (proxyAvailable) { ProxyController proxyController = ProxyController.instance(); await proxyController.clearProxyOverride(); @@ -147,22 +153,21 @@ class _AppWebviewState extends State { ) ]; - Widget body = (App.isWindows && AppWebview.webViewEnvironment == null) - ? FutureBuilder( - future: future, - builder: (context, e) { - if (e.error != null) { - return Center(child: Text("Error: ${e.error}")); - } - if (e.data == null) { - return const Center(child: CircularProgressIndicator()); - } - AppWebview.webViewEnvironment = e.data; - return createWebviewWithEnvironment( - AppWebview.webViewEnvironment); - }, - ) - : createWebviewWithEnvironment(AppWebview.webViewEnvironment); + Widget body = FutureBuilder( + future: future, + builder: (context, e) { + if (e.error != null) { + return Center(child: Text("Error: ${e.error}")); + } + if (e.data == null) { + return const SizedBox(); + } + AppWebview.webViewEnvironment = e.data; + return createWebviewWithEnvironment( + AppWebview.webViewEnvironment, + ); + }, + ); body = Stack( children: [ diff --git a/pubspec.lock b/pubspec.lock index 6f5ba9f..dde4d00 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -307,19 +307,21 @@ packages: flutter_inappwebview: dependency: "direct main" description: - name: flutter_inappwebview - sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5" - url: "https://pub.dev" - source: hosted - version: "6.1.5" + path: flutter_inappwebview + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "6.2.0-beta.3" flutter_inappwebview_android: dependency: transitive description: - name: flutter_inappwebview_android - sha256: "62557c15a5c2db5d195cb3892aab74fcaec266d7b86d59a6f0027abd672cddba" - url: "https://pub.dev" - source: hosted - version: "1.1.3" + path: flutter_inappwebview_android + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "1.2.0-beta.3" flutter_inappwebview_internal_annotations: dependency: transitive description: @@ -331,43 +333,48 @@ packages: flutter_inappwebview_ios: dependency: transitive description: - name: flutter_inappwebview_ios - sha256: "5818cf9b26cf0cbb0f62ff50772217d41ea8d3d9cc00279c45f8aabaa1b4025d" - url: "https://pub.dev" - source: hosted - version: "1.1.2" + path: flutter_inappwebview_ios + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "1.2.0-beta.3" flutter_inappwebview_macos: dependency: transitive description: - name: flutter_inappwebview_macos - sha256: c1fbb86af1a3738e3541364d7d1866315ffb0468a1a77e34198c9be571287da1 - url: "https://pub.dev" - source: hosted - version: "1.1.2" + path: flutter_inappwebview_macos + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "1.2.0-beta.3" flutter_inappwebview_platform_interface: dependency: transitive description: - name: flutter_inappwebview_platform_interface - sha256: cf5323e194096b6ede7a1ca808c3e0a078e4b33cc3f6338977d75b4024ba2500 - url: "https://pub.dev" - source: hosted - version: "1.3.0+1" + path: flutter_inappwebview_platform_interface + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "1.4.0-beta.3" flutter_inappwebview_web: dependency: transitive description: - name: flutter_inappwebview_web - sha256: "55f89c83b0a0d3b7893306b3bb545ba4770a4df018204917148ebb42dc14a598" - url: "https://pub.dev" - source: hosted - version: "1.1.2" + path: flutter_inappwebview_web + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "1.2.0-beta.3" flutter_inappwebview_windows: dependency: transitive description: - name: flutter_inappwebview_windows - sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055" - url: "https://pub.dev" - source: hosted - version: "0.6.0" + path: flutter_inappwebview_windows + ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676" + url: "https://github.com/pichillilorenzo/flutter_inappwebview" + source: git + version: "0.7.0-beta.3" flutter_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 267c905..d1cbe25 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,7 +43,11 @@ dependencies: git: url: https://github.com/wgh136/flutter_desktop_webview path: packages/desktop_webview_window - flutter_inappwebview: ^6.1.5 + flutter_inappwebview: + git: + url: https://github.com/pichillilorenzo/flutter_inappwebview + path: flutter_inappwebview + ref: 0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676 app_links: ^6.3.3 sliver_tools: ^0.2.12 flutter_file_dialog: ^3.0.2