Skip to content

Commit 30c6973

Browse files
author
randommodder
committed
Use more modern library for getting proxies
1 parent 4923895 commit 30c6973

File tree

3 files changed

+31
-274
lines changed

3 files changed

+31
-274
lines changed

lib/main.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:io';
22

33
import 'package:flutter/foundation.dart';
44
import 'package:flutter/material.dart';
5-
import 'package:http_proxy/http_proxy.dart';
5+
import 'package:native_flutter_proxy/native_flutter_proxy.dart';
66
import 'package:hw_manager_flutter/l10n/app_localizations.dart';
77
import 'package:hw_manager_flutter/routes/home_route.dart';
88
import 'package:hw_manager_flutter/shared_preferences.dart';
@@ -13,10 +13,28 @@ void main() async {
1313
WidgetsFlutterBinding.ensureInitialized();
1414
if (!kIsWeb) {
1515
if (Platform.isAndroid || Platform.isIOS) {
16-
final HttpProxy httpProxy = await HttpProxy.createHttpProxy();
17-
HttpOverrides.global = httpProxy;
16+
bool enabled = false;
17+
String? host;
18+
int? port;
19+
try {
20+
final ProxySetting settings = await NativeProxyReader.proxySetting;
21+
enabled = settings.enabled;
22+
host = settings.host;
23+
port = settings.port;
24+
} catch (e) {
25+
if (kDebugMode) {
26+
print(e);
27+
}
28+
}
29+
if (enabled && host != null) {
30+
final proxy = CustomProxy(ipAddress: host, port: port);
31+
proxy.enable();
32+
if (kDebugMode) {
33+
print("proxy enabled");
34+
}
35+
}
1836
}
19-
await SimpleSecureStorage.initialize(const InitializationOptions());
37+
await SimpleSecureStorage.initialize();
2038
} else {
2139
// To secure your data on Flutter web, we have to encrypt it using a password and a salt.
2240
await SimpleSecureStorage.initialize(WebInitializationOptions(

0 commit comments

Comments
 (0)