diff --git a/lib/pages/app.dart b/lib/pages/app.dart index 305274b..ff60517 100644 --- a/lib/pages/app.dart +++ b/lib/pages/app.dart @@ -25,9 +25,32 @@ class AppPage extends StatefulWidget { } class _AppPageState extends State { + late final WebViewController _webViewController; + bool _wasWebViewOpened = false; AppInMemory? prevApp; bool updating = false; + @override + void initState() { + super.initState(); + _webViewController = WebViewController() + ..setJavaScriptMode(JavaScriptMode.unrestricted) + ..setNavigationDelegate( + NavigationDelegate( + onWebResourceError: (WebResourceError error) { + if (error.isForMainFrame == true) { + showError( + ObtainiumError(error.description, unexpected: true), context); + } + }, + onNavigationRequest: (NavigationRequest request) => + request.url.startsWith("rustore://") + ? NavigationDecision.prevent + : NavigationDecision.navigate, + ), + ); + } + @override Widget build(BuildContext context) { var appsProvider = context.watch(); @@ -81,6 +104,11 @@ class _AppPageState extends State { (app?.app.installedVersion != null && app?.app.additionalSettings['versionDetection'] != true); + if (app != null && !_wasWebViewOpened) { + _wasWebViewOpened = true; + _webViewController.loadRequest(Uri.parse(app.app.url)); + } + getInfoColumn() { String versionLines = ''; bool installed = app?.app.installedVersion != null; @@ -340,25 +368,9 @@ class _AppPageState extends State { getAppWebView() => app != null ? WebViewWidget( - controller: WebViewController() - ..setJavaScriptMode(JavaScriptMode.unrestricted) - ..setBackgroundColor(Theme.of(context).colorScheme.surface) - ..setNavigationDelegate( - NavigationDelegate( - onWebResourceError: (WebResourceError error) { - if (error.isForMainFrame == true) { - showError( - ObtainiumError(error.description, unexpected: true), - context); - } - }, - onNavigationRequest: (NavigationRequest request) => - request.url.startsWith("rustore://") - ? NavigationDecision.prevent - : NavigationDecision.navigate, - ), - ) - ..loadRequest(Uri.parse(app.app.url))) + key: ObjectKey(_webViewController), + controller: _webViewController + ..setBackgroundColor(Theme.of(context).colorScheme.surface)) : Container(); showMarkUpdatedDialog() {