diff --git a/lib/bootstrap.dart b/lib/bootstrap.dart index e73046a0..63a767e1 100644 --- a/lib/bootstrap.dart +++ b/lib/bootstrap.dart @@ -6,6 +6,7 @@ import 'package:hiddify/core/app/app.dart'; import 'package:hiddify/core/prefs/prefs.dart'; import 'package:hiddify/data/data_providers.dart'; import 'package:hiddify/features/common/active_profile/active_profile_notifier.dart'; +import 'package:hiddify/features/common/common.dart'; import 'package:hiddify/features/common/window/window_controller.dart'; import 'package:hiddify/features/system_tray/system_tray.dart'; import 'package:hiddify/services/deep_link_service.dart'; @@ -86,6 +87,7 @@ Future initControllers( [ read(activeProfileProvider.future), read(deepLinkServiceProvider.future), + read(runtimeDetailsNotifierProvider.future), if (PlatformUtils.isDesktop) read(systemTrayControllerProvider.future), ], ); diff --git a/lib/features/common/common.dart b/lib/features/common/common.dart index 0f85d1aa..4ac4edcf 100644 --- a/lib/features/common/common.dart +++ b/lib/features/common/common.dart @@ -2,3 +2,4 @@ export 'confirmation_dialogs.dart'; export 'custom_app_bar.dart'; export 'profile_tile.dart'; export 'qr_code_scanner_screen.dart'; +export 'runtime_details.dart'; diff --git a/lib/features/common/runtime_details.dart b/lib/features/common/runtime_details.dart index 0251cfbb..f40aa84c 100644 --- a/lib/features/common/runtime_details.dart +++ b/lib/features/common/runtime_details.dart @@ -32,6 +32,8 @@ class RuntimeDetails with _$RuntimeDetails { required String clashVersion, }) = _RuntimeDetails; + String get fullVersion => version + buildNumber; + factory RuntimeDetails.fromJson(Map json) => _$RuntimeDetailsFromJson(json); } diff --git a/lib/features/home/view/home_page.dart b/lib/features/home/view/home_page.dart index 2b3c2246..f3620844 100644 --- a/lib/features/home/view/home_page.dart +++ b/lib/features/home/view/home_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; import 'package:hiddify/core/core_providers.dart'; import 'package:hiddify/core/router/router.dart'; import 'package:hiddify/domain/failures.dart'; @@ -40,7 +41,13 @@ class HomePage extends HookConsumerWidget { CustomScrollView( slivers: [ NestedTabAppBar( - title: Text(t.general.appTitle.titleCase), + title: Row( + children: [ + Text(t.general.appTitle.titleCase), + const Gap(4), + const AppVersionLabel(), + ], + ), actions: [ IconButton( onPressed: () => const AddProfileRoute().push(context), @@ -82,3 +89,40 @@ class HomePage extends HookConsumerWidget { ); } } + +class AppVersionLabel extends HookConsumerWidget { + const AppVersionLabel({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final theme = Theme.of(context); + + final version = ref.watch( + runtimeDetailsNotifierProvider.select( + (value) => switch (value) { + AsyncData(:final value) => value.fullVersion, + _ => "", + }, + ), + ); + + if (version.isEmpty) return const SizedBox(); + + return Container( + decoration: BoxDecoration( + color: theme.colorScheme.secondaryContainer, + borderRadius: BorderRadius.circular(4), + ), + padding: const EdgeInsets.symmetric( + horizontal: 4, + vertical: 1, + ), + child: Text( + version, + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSecondaryContainer, + ), + ), + ); + } +}