]> git.proxmox.com Git - flutter/pve_flutter_frontend.git/commitdiff
update webview_flutter to 4.2.0
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 24 Apr 2023 08:38:04 +0000 (10:38 +0200)
committerDominik Csapak <d.csapak@proxmox.com>
Mon, 24 Apr 2023 12:18:23 +0000 (14:18 +0200)
the api changed considerably, so we have to rework how we initialize it:

most is now down in the WebViewController instead of the WebView widget
(which now is WebViewWidget). Cookies can only be set globally in the
WebViewCookieManager. Since this is now async, we have to use a
FutureBuilder to wait for it before returning the WebViewWidget

for this to work, we have to update the kotlin_version, gradle and the
android gradle plugin
(flutter 3.7 supports up to agp 7.4[0], which requires at least gradle 7.5[1]
and IIUC for kotlin 1.7.20 we need at least gradle 7.6[2])

0: https://github.com/flutter/flutter/issues/125181#issuecomment-1518238664
1: https://developer.android.com/build/releases/gradle-plugin
2: https://docs.gradle.org/current/userguide/compatibility.html

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
android/build.gradle
android/gradle/wrapper/gradle-wrapper.properties
lib/widgets/pve_console_menu_widget.dart
pubspec.yaml

index 19566e13e8ccb857364d208c0a445836a0a63fe9..1286ce67b5cc5cdd3a92c36e51bcb9d9bdf0048f 100644 (file)
@@ -1,6 +1,6 @@
 buildscript {
     ext {
-        kotlin_version = '1.5.32'
+        kotlin_version = '1.7.20'
         androidXCore = "1.7.0"
     }
     repositories {
@@ -9,7 +9,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:7.1.0'
+        classpath 'com.android.tools.build:gradle:7.4.2'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
     }
 }
index ebac36386fa56a8c91b7106da905aed07df414ec..0732d12500dfc8b31dcb83125f61457c3f03d422 100644 (file)
@@ -1,6 +1,6 @@
-#Tue Dec 07 16:15:51 CET 2021
+#Mon Apr 24 14:18:06 CEST 2023
 distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
 distributionPath=wrapper/dists
-zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
 zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
index ac5ad265f86c1e04911c6ba1fcb73b1f368a0bad..44fad12f51e3e4d1a737ef4d5ac57a78e7417d5e 100644 (file)
@@ -210,39 +210,37 @@ class PVEWebConsole extends StatefulWidget {
 }
 
 class PVEWebConsoleState extends State<PVEWebConsole> {
-  final Completer<WebViewController> _controller =
-      Completer<WebViewController>();
-
   @override
   Widget build(BuildContext context) {
     final ticket = widget.apiClient.credentials.ticket!;
     final baseUrl = widget.apiClient.credentials.apiBaseUrl;
 
-    var consoleUrl = "${baseUrl}/?novnc=1&node=${widget.node}&isFullscreen=true&resize=scale";
+    var consoleUrl =
+        "$baseUrl/?novnc=1&node=${widget.node}&isFullscreen=true&resize=scale";
     if (widget.guestID != null) {
       final consoleType = widget.type == 'lxc' ? 'lxc' : 'kvm';
-      consoleUrl += "&console=${consoleType}&vmid=${widget.guestID}";
+      consoleUrl += "&console=$consoleType&vmid=${widget.guestID}";
     } else {
       consoleUrl += "&console=shell";
     }
-    //debugPrint("url: ${consoleUrl}, ticket: $ticket");
-
-    return SafeArea(
-      child: WebView(
-        javascriptMode: JavascriptMode.unrestricted,
-        backgroundColor: Theme.of(context).colorScheme.background,
-        initialCookies: <WebViewCookie>[
-          WebViewCookie(
-            name: 'PVEAuthCookie',
-            value: ticket,
-            domain: baseUrl.origin,
-          )
-        ],
-        onWebViewCreated: (WebViewController webViewController) {
-          _controller.complete(webViewController);
-          webViewController.loadUrl(consoleUrl);
-        },
-      ),
-    );
+
+    final controller = WebViewController()
+      ..setJavaScriptMode(JavaScriptMode.unrestricted)
+      ..setBackgroundColor(Theme.of(context).colorScheme.background)
+      ..loadRequest(Uri.parse(consoleUrl));
+
+    return FutureBuilder(
+        future: WebViewCookieManager().setCookie(WebViewCookie(
+          name: 'PVEAuthCookie',
+          value: ticket,
+          domain: baseUrl.origin,
+        )),
+        builder: (context, snapshot) {
+          return SafeArea(
+            child: WebViewWidget(
+              controller: controller,
+            ),
+          );
+        });
   }
 }
index 03c4eb62e8fb10dc96fc585b71068bcd84b90fc5..55dbb33e464b708f799ec52e183315f2f1534e9a 100644 (file)
@@ -34,7 +34,7 @@ dependencies:
   intl: ^0.17.0
   package_info_plus: ^1.4.0
   path_provider: ^2.0.8
-  webview_flutter: ^3.0.0
+  webview_flutter: ^4.2.0
   proxmox_dart_api_client:
     path: ../proxmox_dart_api_client
   proxmox_login_manager: