From 4bd268e392239da05eb56b65c2e20023e17862d9 Mon Sep 17 00:00:00 2001 From: Hiddify Date: Thu, 22 Feb 2024 17:35:29 +0100 Subject: [PATCH] fix: intro page bug and fakepacket delay bug --- lib/core/router/routes.dart | 2 +- .../overview/warp_options_widgets.dart | 2 +- lib/features/intro/widget/intro_page.dart | 35 ++++++++++++++----- libcore | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/core/router/routes.dart b/lib/core/router/routes.dart index 5e2423c4..f7a1f349 100644 --- a/lib/core/router/routes.dart +++ b/lib/core/router/routes.dart @@ -154,7 +154,7 @@ class IntroRoute extends GoRouteData { @override Page buildPage(BuildContext context, GoRouterState state) { - return const MaterialPage( + return MaterialPage( fullscreenDialog: true, name: name, child: IntroPage(), diff --git a/lib/features/config_option/overview/warp_options_widgets.dart b/lib/features/config_option/overview/warp_options_widgets.dart index e767ad4d..22c33157 100644 --- a/lib/features/config_option/overview/warp_options_widgets.dart +++ b/lib/features/config_option/overview/warp_options_widgets.dart @@ -185,7 +185,7 @@ class WarpOptionsTiles extends HookConsumerWidget { if (warpNoiseDelay == null) return; await onChange( ConfigOptionPatch( - warpNoise: + warpNoiseDelay: OptionalRange.tryParse(warpNoiseDelay, allowEmpty: true), ), ); diff --git a/lib/features/intro/widget/intro_page.dart b/lib/features/intro/widget/intro_page.dart index 60d1729a..78446b5e 100644 --- a/lib/features/intro/widget/intro_page.dart +++ b/lib/features/intro/widget/intro_page.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/gestures.dart'; +import 'package:hiddify/core/http_client/dio_http_client.dart'; import 'package:timezone_to_country/timezone_to_country.dart'; import 'package:flutter/material.dart'; @@ -15,19 +16,22 @@ import 'package:hiddify/features/common/general_pref_tiles.dart'; import 'package:hiddify/gen/assets.gen.dart'; import 'package:hiddify/utils/utils.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:http/http.dart' as http; + import 'package:sliver_tools/sliver_tools.dart'; class IntroPage extends HookConsumerWidget with PresLogger { - const IntroPage({super.key}); - + bool locationInfoLoaded = false; + IntroPage({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final t = ref.watch(translationsProvider); final isStarting = useState(false); - autoSelectRegion(ref) - .then((value) => loggy.debug("Auto Region selection finished!")); + if (!locationInfoLoaded) { + autoSelectRegion(ref) + .then((value) => loggy.debug("Auto Region selection finished!")); + locationInfoLoaded = true; + } return Scaffold( body: SafeArea( child: CustomScrollView( @@ -132,16 +136,25 @@ class IntroPage extends HookConsumerWidget with PresLogger { .changeLocale(regionLocale.locale); return; } catch (e) { - loggy.warning('Could not get the local country code based on timezone'); + loggy.warning( + 'Could not get the local country code based on timezone', + e, + ); } try { - final response = await http.get(Uri.parse('https://api.ip.sb/json/')); + final DioHttpClient client = DioHttpClient( + timeout: const Duration(seconds: 2), + userAgent: + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0", + debug: true); + final response = + await client.get>('https://api.ip.sb/geoip/'); if (response.statusCode == 200) { - final jsonData = jsonDecode(response.body); + final jsonData = response.data!; final regionLocale = - _getRegionLocale(jsonData['country']?.toString() ?? ""); + _getRegionLocale(jsonData['country_code']?.toString() ?? ""); loggy.debug( 'Region: ${regionLocale.region} Locale: ${regionLocale.locale}', @@ -170,6 +183,10 @@ class IntroPage extends HookConsumerWidget with PresLogger { return RegionLocale(Region.ru, AppLocale.ru); case "AF": return RegionLocale(Region.af, AppLocale.fa); + case "BR": + return RegionLocale(Region.other, AppLocale.ptBr); + case "TR": + return RegionLocale(Region.other, AppLocale.tr); default: return RegionLocale(Region.other, AppLocale.en); } diff --git a/libcore b/libcore index a50b0d4d..48297a74 160000 --- a/libcore +++ b/libcore @@ -1 +1 @@ -Subproject commit a50b0d4da89cfc3aa18123865e636535cf283993 +Subproject commit 48297a74aecec0410120e52001cc30d84d77c875