Skip to content

Commit

Permalink
fix #127
Browse files Browse the repository at this point in the history
  • Loading branch information
wgh136 committed Jan 6, 2025
1 parent 99a3788 commit fb1b017
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions lib/pages/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -83,6 +84,33 @@ class _AppWebviewState extends State<AppWebview> {

double _progress = 0;

late var future = _createWebviewEnvironment();

Future<WebViewEnvironment> _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 = [
Expand Down Expand Up @@ -121,20 +149,17 @@ class _AppWebviewState extends State<AppWebview> {

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);
Expand Down

0 comments on commit fb1b017

Please sign in to comment.