Skip to content

Commit 76dfe63

Browse files
author
code3-dev
committed
fix sort
1 parent def23ab commit 76dfe63

14 files changed

+461
-205
lines changed

android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727
minSdk = flutter.minSdkVersion
2828
targetSdk = flutter.targetSdkVersion
2929
versionCode = 14
30-
versionName = "2.2.0"
30+
versionName = "2.3.0"
3131
}
3232

3333
buildTypes {

lib/models/app_update.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AppUpdate {
66
final String messText;
77

88
// Current app version - manually set
9-
static const String currentAppVersion = '2.2.0';
9+
static const String currentAppVersion = '2.3.0';
1010

1111
AppUpdate({required this.version, required this.url, required this.messText});
1212

@@ -38,8 +38,12 @@ class AppUpdate {
3838
List<int> newer = newVersion.split('.').map(int.parse).toList();
3939

4040
// Ensure both lists have at least 3 elements
41-
while (current.length < 3) current.add(0);
42-
while (newer.length < 3) newer.add(0);
41+
while (current.length < 3) {
42+
current.add(0);
43+
}
44+
while (newer.length < 3) {
45+
newer.add(0);
46+
}
4347

4448
for (int i = 0; i < 3; i++) {
4549
if (newer[i] > current[i]) {

lib/providers/v2ray_provider.dart

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/widgets.dart';
2-
import 'package:shared_preferences/shared_preferences.dart';
32
import '../models/v2ray_config.dart';
43
import '../models/subscription.dart';
54
import '../services/v2ray_service.dart';
@@ -8,7 +7,7 @@ import '../services/server_service.dart';
87
class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
98
final V2RayService _v2rayService = V2RayService();
109
final ServerService _serverService = ServerService();
11-
bool status_ping_only = false;
10+
bool statusPingOnly = false;
1211
List<V2RayConfig> _configs = [];
1312
List<Subscription> _subscriptions = [];
1413
V2RayConfig? _selectedConfig;
@@ -69,7 +68,7 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
6968

7069
// If we couldn't find the exact active config in our list,
7170
// try to find a matching one by address and port
72-
if (_selectedConfig == null && activeConfig != null) {
71+
if (_selectedConfig == null) {
7372
for (var config in _configs) {
7473
if (config.address == activeConfig.address &&
7574
config.port == activeConfig.port) {
@@ -576,7 +575,12 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
576575
try {
577576
// Disconnect from current server if connected
578577
if (_v2rayService.activeConfig != null) {
579-
await _v2rayService.disconnect();
578+
try {
579+
await _v2rayService.disconnect();
580+
} catch (e) {
581+
debugPrint('Error disconnecting from current server: $e');
582+
// Continue with connection attempt even if disconnect failed
583+
}
580584
}
581585

582586
// Try to connect with automatic retry
@@ -585,26 +589,40 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
585589

586590
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
587591
try {
588-
// Connect to server
589-
success = await _v2rayService.connect(config, _isProxyMode);
592+
debugPrint('Connection attempt $attempt/$maxAttempts for ${config.remark}');
593+
594+
// Connect to server with timeout
595+
success = await _v2rayService.connect(config, _isProxyMode)
596+
.timeout(
597+
const Duration(seconds: 30), // Timeout for connection
598+
onTimeout: () {
599+
debugPrint('Connection timeout for ${config.remark}');
600+
return false;
601+
},
602+
);
590603

591604
if (success) {
592-
// Connection successful, break the retry loop
605+
debugPrint('Connection successful for ${config.remark}');
593606
break;
594607
} else {
595608
// Connection failed but no exception was thrown
596-
lastError = 'Failed to connect to server on attempt $attempt';
597-
print(lastError);
609+
lastError = 'Failed to connect to ${config.remark} on attempt $attempt';
610+
debugPrint(lastError);
598611

599612
// If this is not the last attempt, wait before retrying
600613
if (attempt < maxAttempts) {
601614
await Future.delayed(Duration(seconds: retryDelaySeconds));
602615
}
603616
}
604617
} catch (e) {
605-
// Exception during connection attempt
606-
lastError = 'Error on connection attempt $attempt: $e';
607-
print(lastError);
618+
// Check if this is a timeout-related error
619+
if (e.toString().contains('timeout')) {
620+
lastError = 'Connection timeout on attempt $attempt: $e';
621+
debugPrint(lastError);
622+
} else {
623+
lastError = 'Error on connection attempt $attempt: $e';
624+
debugPrint(lastError);
625+
}
608626

609627
// If this is not the last attempt, wait before retrying
610628
if (attempt < maxAttempts) {
@@ -614,29 +632,48 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
614632
}
615633

616634
if (success) {
617-
// Wait for 3 seconds as requested
618-
await Future.delayed(const Duration(seconds: 3));
635+
try {
636+
// Wait for connection to stabilize
637+
await Future.delayed(const Duration(seconds: 2)); // Reduced from 3 to 2 seconds
619638

620-
// Update config status
621-
for (int i = 0; i < _configs.length; i++) {
622-
if (_configs[i].id == config.id) {
623-
_configs[i].isConnected = true;
624-
} else {
625-
_configs[i].isConnected = false;
639+
// Update config status safely
640+
for (int i = 0; i < _configs.length; i++) {
641+
if (_configs[i].id == config.id) {
642+
_configs[i].isConnected = true;
643+
} else {
644+
_configs[i].isConnected = false;
645+
}
626646
}
627-
}
628-
_selectedConfig = config;
647+
_selectedConfig = config;
629648

630-
// Persist the changes
631-
await _v2rayService.saveConfigs(_configs);
649+
// Persist the changes with error handling
650+
try {
651+
await _v2rayService.saveConfigs(_configs);
652+
} catch (e) {
653+
debugPrint('Error saving configs after connection: $e');
654+
// Don't fail the connection for this
655+
}
632656

633-
// Reset usage statistics when connecting to a new server
634-
await _v2rayService.resetUsageStats();
657+
// Reset usage statistics when connecting to a new server
658+
try {
659+
await _v2rayService.resetUsageStats();
660+
} catch (e) {
661+
debugPrint('Error resetting usage stats: $e');
662+
// Don't fail the connection for this
663+
}
664+
665+
debugPrint('Successfully connected to ${config.remark}');
666+
} catch (e) {
667+
debugPrint('Error in post-connection setup: $e');
668+
// Connection succeeded but post-setup failed
669+
_setError('Connected but failed to update settings: $e');
670+
}
635671
} else {
636-
_setError('Failed to connect after multiple attempts');
672+
_setError('Failed to connect to ${config.remark} after $maxAttempts attempts: $lastError');
637673
}
638674
} catch (e) {
639-
_setError('Error in connection process: $e');
675+
debugPrint('Unexpected error in connection process: $e');
676+
_setError('Unexpected error connecting to ${config.remark}: $e');
640677
} finally {
641678
_isConnecting = false;
642679
notifyListeners();
@@ -649,7 +686,7 @@ class V2RayProvider with ChangeNotifier, WidgetsBindingObserver {
649686

650687
try {
651688
await _v2rayService.disconnect();
652-
status_ping_only = false;
689+
statusPingOnly = false;
653690
// Update config status
654691
for (int i = 0; i < _configs.length; i++) {
655692
_configs[i].isConnected = false;

lib/screens/about_screen.dart

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

4949
// App Version
5050
const Text(
51-
'Version 2.2.0',
51+
'Version 2.3.0',
5252
style: TextStyle(fontSize: 16, color: Colors.grey),
5353
),
5454

lib/screens/blocked_apps_screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
import 'package:shared_preferences/shared_preferences.dart';
33
import '../theme/app_theme.dart';
44
import '../services/v2ray_service.dart';
5-
import 'dart:io';
65
import 'package:flutter/foundation.dart';
76

87
class BlockedAppsScreen extends StatefulWidget {

lib/screens/home_screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
3-
import 'package:shared_preferences/shared_preferences.dart';
43
import '../providers/v2ray_provider.dart';
54
import '../widgets/connection_button.dart';
65
import '../widgets/server_selector.dart';

lib/screens/host_checker_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class _HostCheckerScreenState extends State<HostCheckerScreen> {
8282
.timeout(
8383
const Duration(seconds: 10),
8484
onTimeout: () {
85-
throw TimeoutException('Request timed out after 10 seconds');
85+
throw Exception('Request timed out after 10 seconds');
8686
},
8787
);
8888

lib/screens/ip_info_screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:provider/provider.dart';
33
import 'package:http/http.dart' as http;
44
import 'dart:convert';
55
import '../providers/v2ray_provider.dart';
6-
import '../services/v2ray_service.dart';
76
import '../theme/app_theme.dart';
87

98
class IpInfoScreen extends StatefulWidget {

lib/screens/main_navigation_screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
33
import 'package:url_launcher/url_launcher.dart';
4-
import '../providers/telegram_proxy_provider.dart';
54
import '../providers/v2ray_provider.dart';
65
import '../theme/app_theme.dart';
76
import '../widgets/error_snackbar.dart';

0 commit comments

Comments
 (0)