[windows] Replace desktop_webview_window with flutter_inappwebview

This commit is contained in:
2025-02-11 20:08:02 +08:00
parent 53e5ebbbf6
commit 51c2bf0d6f
5 changed files with 74 additions and 58 deletions

View File

@@ -118,7 +118,7 @@ void passCloudflare(CloudflareException e, void Function() onFinished) async {
// windows version of package `flutter_inappwebview` cannot get some cookies // windows version of package `flutter_inappwebview` cannot get some cookies
// Using DesktopWebview instead // Using DesktopWebview instead
if (App.isLinux || App.isWindows) { if (App.isLinux) {
var webview = DesktopWebview( var webview = DesktopWebview(
initialUrl: url, initialUrl: url,
onTitleChange: (title, controller) async { onTitleChange: (title, controller) async {

View File

@@ -1011,7 +1011,7 @@ class _LoginPageState extends State<_LoginPage> {
if (widget.config.loginWebsite != null) if (widget.config.loginWebsite != null)
TextButton( TextButton(
onPressed: () { onPressed: () {
if (App.isWindows || App.isLinux) { if (App.isLinux) {
loginWithWebview2(); loginWithWebview2();
} else { } else {
loginWithWebview(); loginWithWebview();
@@ -1127,7 +1127,7 @@ class _LoginPageState extends State<_LoginPage> {
} }
} }
// for windows and linux // for linux
void loginWithWebview2() async { void loginWithWebview2() async {
if (!await DesktopWebview.isAvailable()) { if (!await DesktopWebview.isAvailable()) {
context.showMessage(message: "Webview is not available".tl); context.showMessage(message: "Webview is not available".tl);

View File

@@ -25,8 +25,13 @@ extension WebviewExtension on InAppWebViewController {
if (url[url.length - 1] == '/') { if (url[url.length - 1] == '/') {
url = url.substring(0, url.length - 1); url = url.substring(0, url.length - 1);
} }
CookieManager cookieManager = CookieManager.instance(); CookieManager cookieManager = CookieManager.instance(
final cookies = await cookieManager.getCookies(url: WebUri(url)); webViewEnvironment: AppWebview.webViewEnvironment,
);
final cookies = await cookieManager.getCookies(
url: WebUri(url),
webViewController: this,
);
var res = <io.Cookie>[]; var res = <io.Cookie>[];
for (var cookie in cookies) { for (var cookie in cookies) {
var c = io.Cookie(cookie.name, cookie.value); var c = io.Cookie(cookie.name, cookie.value);
@@ -90,7 +95,8 @@ class _AppWebviewState extends State<AppWebview> {
var proxy = appdata.settings['proxy'].toString(); var proxy = appdata.settings['proxy'].toString();
if (proxy != "system" && proxy != "direct") { if (proxy != "system" && proxy != "direct") {
var proxyAvailable = await WebViewFeature.isFeatureSupported( var proxyAvailable = await WebViewFeature.isFeatureSupported(
WebViewFeature.PROXY_OVERRIDE); WebViewFeature.PROXY_OVERRIDE,
);
if (proxyAvailable) { if (proxyAvailable) {
ProxyController proxyController = ProxyController.instance(); ProxyController proxyController = ProxyController.instance();
await proxyController.clearProxyOverride(); await proxyController.clearProxyOverride();
@@ -147,22 +153,21 @@ class _AppWebviewState extends State<AppWebview> {
) )
]; ];
Widget body = (App.isWindows && AppWebview.webViewEnvironment == null) Widget body = FutureBuilder(
? FutureBuilder( future: future,
future: future, builder: (context, e) {
builder: (context, e) { if (e.error != null) {
if (e.error != null) { return Center(child: Text("Error: ${e.error}"));
return Center(child: Text("Error: ${e.error}")); }
} if (e.data == null) {
if (e.data == null) { return const SizedBox();
return const Center(child: CircularProgressIndicator()); }
} AppWebview.webViewEnvironment = e.data;
AppWebview.webViewEnvironment = e.data; return createWebviewWithEnvironment(
return createWebviewWithEnvironment( AppWebview.webViewEnvironment,
AppWebview.webViewEnvironment); );
}, },
) );
: createWebviewWithEnvironment(AppWebview.webViewEnvironment);
body = Stack( body = Stack(
children: [ children: [

View File

@@ -307,19 +307,21 @@ packages:
flutter_inappwebview: flutter_inappwebview:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_inappwebview path: flutter_inappwebview
sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5" ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "6.1.5" source: git
version: "6.2.0-beta.3"
flutter_inappwebview_android: flutter_inappwebview_android:
dependency: transitive dependency: transitive
description: description:
name: flutter_inappwebview_android path: flutter_inappwebview_android
sha256: "62557c15a5c2db5d195cb3892aab74fcaec266d7b86d59a6f0027abd672cddba" ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "1.1.3" source: git
version: "1.2.0-beta.3"
flutter_inappwebview_internal_annotations: flutter_inappwebview_internal_annotations:
dependency: transitive dependency: transitive
description: description:
@@ -331,43 +333,48 @@ packages:
flutter_inappwebview_ios: flutter_inappwebview_ios:
dependency: transitive dependency: transitive
description: description:
name: flutter_inappwebview_ios path: flutter_inappwebview_ios
sha256: "5818cf9b26cf0cbb0f62ff50772217d41ea8d3d9cc00279c45f8aabaa1b4025d" ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "1.1.2" source: git
version: "1.2.0-beta.3"
flutter_inappwebview_macos: flutter_inappwebview_macos:
dependency: transitive dependency: transitive
description: description:
name: flutter_inappwebview_macos path: flutter_inappwebview_macos
sha256: c1fbb86af1a3738e3541364d7d1866315ffb0468a1a77e34198c9be571287da1 ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "1.1.2" source: git
version: "1.2.0-beta.3"
flutter_inappwebview_platform_interface: flutter_inappwebview_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: flutter_inappwebview_platform_interface path: flutter_inappwebview_platform_interface
sha256: cf5323e194096b6ede7a1ca808c3e0a078e4b33cc3f6338977d75b4024ba2500 ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "1.3.0+1" source: git
version: "1.4.0-beta.3"
flutter_inappwebview_web: flutter_inappwebview_web:
dependency: transitive dependency: transitive
description: description:
name: flutter_inappwebview_web path: flutter_inappwebview_web
sha256: "55f89c83b0a0d3b7893306b3bb545ba4770a4df018204917148ebb42dc14a598" ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "1.1.2" source: git
version: "1.2.0-beta.3"
flutter_inappwebview_windows: flutter_inappwebview_windows:
dependency: transitive dependency: transitive
description: description:
name: flutter_inappwebview_windows path: flutter_inappwebview_windows
sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055" ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
url: "https://pub.dev" resolved-ref: "0aaf7a0bfc01d61a4d1453cefb57fb6783b6e676"
source: hosted url: "https://github.com/pichillilorenzo/flutter_inappwebview"
version: "0.6.0" source: git
version: "0.7.0-beta.3"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:

View File

@@ -43,7 +43,11 @@ dependencies:
git: git:
url: https://github.com/wgh136/flutter_desktop_webview url: https://github.com/wgh136/flutter_desktop_webview
path: packages/desktop_webview_window 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 app_links: ^6.3.3
sliver_tools: ^0.2.12 sliver_tools: ^0.2.12
flutter_file_dialog: ^3.0.2 flutter_file_dialog: ^3.0.2