Skip to content

Commit 6d6f0eb

Browse files
author
code3-dev
committed
fix bugs - add dns settings
1 parent 82ca302 commit 6d6f0eb

File tree

9 files changed

+540
-45
lines changed

9 files changed

+540
-45
lines changed

android/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ android {
2626
// For more information, see: https://flutter.dev/to/review-gradle-config.
2727
minSdk = flutter.minSdkVersion
2828
targetSdk = flutter.targetSdkVersion
29-
versionCode = 5
30-
versionName = "1.5.0"
29+
versionCode = 6
30+
versionName = "1.6.0"
3131
}
3232

3333
buildTypes {

lib/models/v2ray_config.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class V2RayConfig {
66
final String configType; // vmess, vless, etc.
77
final String fullConfig;
88
bool isConnected;
9+
bool isProxyMode;
910

1011
V2RayConfig({
1112
required this.id,
@@ -15,6 +16,7 @@ class V2RayConfig {
1516
required this.configType,
1617
required this.fullConfig,
1718
this.isConnected = false,
19+
this.isProxyMode = false,
1820
});
1921

2022
Map<String, dynamic> toJson() {
@@ -26,6 +28,7 @@ class V2RayConfig {
2628
'configType': configType,
2729
'fullConfig': fullConfig,
2830
'isConnected': isConnected,
31+
'isProxyMode': isProxyMode,
2932
};
3033
}
3134

@@ -38,6 +41,7 @@ class V2RayConfig {
3841
configType: json['configType'],
3942
fullConfig: json['fullConfig'],
4043
isConnected: json['isConnected'] ?? false,
44+
isProxyMode: json['isProxyMode'] ?? false,
4145
);
4246
}
4347
}

lib/providers/v2ray_provider.dart

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
5151
// Load servers from the default URL without creating a default subscription
5252
await fetchServers();
5353

54+
// Update all subscriptions on app start
55+
await updateAllSubscriptions();
56+
5457
// Fetch the current notification status to sync with the app
5558
await fetchNotificationStatus();
5659

@@ -134,8 +137,17 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
134137
final servers = await _serverService.fetchServers(customUrl: customUrl);
135138

136139
if (servers.isNotEmpty) {
137-
// Load and display servers immediately
138-
_configs = servers;
140+
// Get all subscription config IDs to preserve them
141+
final subscriptionConfigIds = <String>{};
142+
for (var subscription in _subscriptions) {
143+
subscriptionConfigIds.addAll(subscription.configIds);
144+
}
145+
146+
// Keep existing subscription configs
147+
final subscriptionConfigs = _configs.where((c) => subscriptionConfigIds.contains(c.id)).toList();
148+
149+
// Add default servers to the configs list
150+
_configs = [...subscriptionConfigs, ...servers];
139151

140152
// Save configs and update UI immediately to show servers
141153
await _v2rayService.saveConfigs(_configs);
@@ -470,14 +482,51 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
470482
_errorMessage = '';
471483
notifyListeners();
472484

485+
// Maximum number of connection attempts
486+
const int maxAttempts = 3;
487+
// Delay between attempts in seconds
488+
const int retryDelaySeconds = 1;
489+
473490
try {
474491
// Disconnect from current server if connected
475492
if (_v2rayService.activeConfig != null) {
476493
await _v2rayService.disconnect();
477494
}
478495

479-
// Connect to new server
480-
final success = await _v2rayService.connect(config);
496+
// Try to connect with automatic retry
497+
bool success = false;
498+
String lastError = '';
499+
500+
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
501+
try {
502+
// Connect to server
503+
success = await _v2rayService.connect(config);
504+
505+
if (success) {
506+
// Connection successful, break the retry loop
507+
break;
508+
} else {
509+
// Connection failed but no exception was thrown
510+
lastError = 'Failed to connect to server on attempt $attempt';
511+
print(lastError);
512+
513+
// If this is not the last attempt, wait before retrying
514+
if (attempt < maxAttempts) {
515+
await Future.delayed(Duration(seconds: retryDelaySeconds));
516+
}
517+
}
518+
} catch (e) {
519+
// Exception during connection attempt
520+
lastError = 'Error on connection attempt $attempt: $e';
521+
print(lastError);
522+
523+
// If this is not the last attempt, wait before retrying
524+
if (attempt < maxAttempts) {
525+
await Future.delayed(Duration(seconds: retryDelaySeconds));
526+
}
527+
}
528+
}
529+
481530
if (success) {
482531
// Wait for 3 seconds as requested
483532
await Future.delayed(const Duration(seconds: 3));
@@ -498,10 +547,10 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
498547
// Reset usage statistics when connecting to a new server
499548
await _v2rayService.resetUsageStats();
500549
} else {
501-
_setError('Failed to connect to server');
550+
_setError('Failed to connect after multiple attempts');
502551
}
503552
} catch (e) {
504-
_setError('Error connecting to server: $e');
553+
_setError('Error in connection process: $e');
505554
} finally {
506555
_isConnecting = false;
507556
notifyListeners();

lib/screens/about_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AboutScreen extends StatelessWidget {
5151

5252
// App Version
5353
const Text(
54-
'Version 1.5.0',
54+
'Version 1.6.0',
5555
style: TextStyle(fontSize: 16, color: Colors.grey),
5656
),
5757

lib/screens/server_selection_screen.dart

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,34 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
6969
backgroundColor: AppTheme.primaryDark,
7070
elevation: 0,
7171
actions: [
72-
if (_selectedFilter == 'All')
73-
IconButton(
74-
icon: const Icon(Icons.refresh),
75-
onPressed: () async {
76-
try {
77-
// Show loading indicator
78-
ScaffoldMessenger.of(context).showSnackBar(
79-
const SnackBar(content: Text('Updating servers...'), duration: Duration(seconds: 1)),
80-
);
81-
72+
IconButton(
73+
icon: const Icon(Icons.refresh),
74+
onPressed: () async {
75+
try {
76+
// Show loading indicator
77+
ScaffoldMessenger.of(context).showSnackBar(
78+
const SnackBar(content: Text('Updating servers...'), duration: Duration(seconds: 1)),
79+
);
80+
81+
if (_selectedFilter == 'All') {
8282
// Update all subscriptions when 'All' is selected
8383
await provider.updateAllSubscriptions();
84+
} else if (_selectedFilter != 'Default') {
85+
// Update individual subscription
86+
final subscription = subscriptions.firstWhere(
87+
(sub) => sub.name == _selectedFilter,
88+
orElse: () => Subscription(id: '', name: '', url: '', lastUpdated: DateTime.now(), configIds: []),
89+
);
8490

85-
// Always check if there was an error
91+
if (subscription.id.isNotEmpty) {
92+
await provider.updateSubscription(subscription);
93+
}
94+
}
95+
96+
// Refresh the UI to show updated server list
97+
setState(() {});
98+
99+
// Always check if there was an error
86100
if (provider.errorMessage.isNotEmpty) {
87101
ScaffoldMessenger.of(context).showSnackBar(
88102
SnackBar(

lib/screens/tools_screen.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'ip_info_screen.dart';
55
import 'host_checker_screen.dart';
66
import 'speedtest_screen.dart';
77
import 'subscription_management_screen.dart';
8+
import 'vpn_settings_screen.dart';
89

910
class ToolsScreen extends StatelessWidget {
1011
const ToolsScreen({Key? key}) : super(key: key);
@@ -77,6 +78,20 @@ class ToolsScreen extends StatelessWidget {
7778
);
7879
},
7980
),
81+
_buildToolCard(
82+
context,
83+
title: 'VPN Settings',
84+
description: 'Configure bypass subnets and other VPN options',
85+
icon: Icons.settings,
86+
onTap: () {
87+
Navigator.push(
88+
context,
89+
MaterialPageRoute(
90+
builder: (context) => const VpnSettingsScreen(),
91+
),
92+
);
93+
},
94+
),
8095
// Add more tools here in the future
8196
],
8297
),

0 commit comments

Comments
 (0)