diff --git a/lib/pages/webview.dart b/lib/pages/webview.dart index e0c6349..e6a4320 100644 --- a/lib/pages/webview.dart +++ b/lib/pages/webview.dart @@ -8,6 +8,7 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:venera/components/components.dart'; import 'package:venera/foundation/app.dart'; +import 'package:venera/foundation/appdata.dart'; import 'package:venera/network/app_dio.dart'; import 'package:venera/utils/ext.dart'; import 'package:venera/utils/translations.dart'; @@ -83,6 +84,33 @@ class _AppWebviewState extends State { double _progress = 0; + late var future = _createWebviewEnvironment(); + + Future _createWebviewEnvironment() async { + var proxy = appdata.settings['proxy'].toString(); + if (proxy != "system" && proxy != "direct") { + var proxyAvailable = await WebViewFeature.isFeatureSupported( + WebViewFeature.PROXY_OVERRIDE); + if (proxyAvailable) { + ProxyController proxyController = ProxyController.instance(); + await proxyController.clearProxyOverride(); + if (!proxy.contains("://")) { + proxy = "http://$proxy"; + } + await proxyController.setProxyOverride( + settings: ProxySettings( + proxyRules: [ProxyRule(url: proxy)], + ), + ); + } + } + return WebViewEnvironment.create( + settings: WebViewEnvironmentSettings( + userDataFolder: "${App.dataPath}\\webview", + ), + ); + } + @override Widget build(BuildContext context) { final actions = [ @@ -121,20 +149,17 @@ class _AppWebviewState extends State { Widget body = (App.isWindows && AppWebview.webViewEnvironment == null) ? FutureBuilder( - future: WebViewEnvironment.create( - settings: WebViewEnvironmentSettings( - userDataFolder: "${App.dataPath}\\webview", - ), - ), + future: future, builder: (context, e) { - if(e.error != null) { + if (e.error != null) { return Center(child: Text("Error: ${e.error}")); } - if(e.data == null) { + if (e.data == null) { return const Center(child: CircularProgressIndicator()); } AppWebview.webViewEnvironment = e.data; - return createWebviewWithEnvironment(AppWebview.webViewEnvironment); + return createWebviewWithEnvironment( + AppWebview.webViewEnvironment); }, ) : createWebviewWithEnvironment(AppWebview.webViewEnvironment);