diff --git a/lib/context.dart b/lib/context.dart index c7c6218..81e225d 100644 --- a/lib/context.dart +++ b/lib/context.dart @@ -1,7 +1,7 @@ +import 'package:retro/utils/git.dart'; + class RetroContext { static const String versionName = '0.2.0'; static const int versionCode = 0; - static const String branch = 'main'; - static const String commitHash = '66e4c03'; - static const String commitDate = '2024-06-03'; -} \ No newline at end of file + static late GitInfo git; +} diff --git a/lib/features/create/create_selection/games/games_selection_screen.dart b/lib/features/create/create_selection/games/games_selection_screen.dart index 512369a..fe3d4b9 100644 --- a/lib/features/create/create_selection/games/games_selection_screen.dart +++ b/lib/features/create/create_selection/games/games_selection_screen.dart @@ -31,14 +31,14 @@ class _GameSelectionScreenState extends State { children: [ OptionCard( text: i18n.gameSelectionScreenSoh_title, - icon: FontAwesomeIcons.puzzlePiece, + icon: Icons.directions_boat_filled_rounded, onTap: () { Navigator.of(context).pushNamed('/game_selection/soh'); }, ), OptionCard( text: i18n.gameSelectionScreen2Ship_title, - icon: FontAwesomeIcons.drum, + icon: Icons.dark_mode, onTap: () { ScaffoldMessenger.of(context).showSnackBar(SnackBar( backgroundColor: const Color.fromARGB(255, 249, 210, 144), diff --git a/lib/features/home/home_screen.dart b/lib/features/home/home_screen.dart index 4e4bbfa..f2c3ce3 100644 --- a/lib/features/home/home_screen.dart +++ b/lib/features/home/home_screen.dart @@ -119,11 +119,11 @@ class _HomeScreenState extends State { ), const SizedBox(height: 40), Text( - '${RetroContext.commitHash} - ${RetroContext.branch}', + '${RetroContext.git.commitHash} - ${RetroContext.git.branch}', style: textTheme.titleSmall?.copyWith(color: colorScheme.onSurface.withOpacity(0.2)), ), Text( - RetroContext.commitDate, + RetroContext.git.commitDate, style: textTheme.titleSmall?.copyWith(color: colorScheme.onSurface.withOpacity(0.2)), ), ], diff --git a/lib/main.dart b/lib/main.dart index 4e1b9e8..4ba3e71 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:provider/provider.dart'; +import 'package:retro/context.dart'; import 'package:retro/features/create/create_custom/create_custom_screen.dart'; import 'package:retro/features/create/create_custom/create_custom_viewmodel.dart'; import 'package:retro/features/create/create_custom_sequences/create_custom_sequences_screen.dart'; @@ -24,9 +25,10 @@ import 'package:retro/features/inspect_otr/inspect_otr_screen.dart'; import 'package:retro/features/inspect_otr/inspect_otr_viewmodel.dart'; import 'package:retro/ui/components/ephemeral_bar.dart'; import 'package:retro/ui/theme/theme.dart'; +import 'package:retro/utils/git.dart'; import 'package:window_size/window_size.dart'; -void main() { +void main() async { WidgetsFlutterBinding.ensureInitialized(); if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { setWindowTitle('Retro'); @@ -34,6 +36,8 @@ void main() { setWindowMaxSize(Size.infinite); } + RetroContext.git = await GitLoader.getGitInfo(); + runApp(const Retro()); } diff --git a/lib/utils/git.dart b/lib/utils/git.dart new file mode 100644 index 0000000..53ab005 --- /dev/null +++ b/lib/utils/git.dart @@ -0,0 +1,26 @@ +import 'package:flutter/services.dart'; +import 'package:intl/intl.dart'; + +class GitInfo { + + GitInfo({required this.branch, required this.commitHash, this.commitDate = ''}); + + final String branch; + final String commitHash; + final String commitDate; +} + +class GitLoader { + + static final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm:ss'); + + static Future getGitInfo() async { + final head = (await rootBundle.loadString('.git/HEAD')).trim(); + final commitId = (await rootBundle.loadString('.git/ORIG_HEAD')).substring(0, 7); + final commitDate = (await rootBundle.loadString('.git/logs/HEAD')).split('\n').first.split(' ')[4]; + final date = DateTime.fromMillisecondsSinceEpoch(int.parse(commitDate) * 1000); + final branch = head.split('/').last; + + return GitInfo(branch: branch, commitHash: commitId, commitDate: _dateFormat.format(date)); + } +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 981c091..5d65d71 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -101,6 +101,10 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - assets/ + - .git/HEAD # This file points out the current branch of the project. + - .git/ORIG_HEAD # This file points to the commit id at origin (last commit id of the remote repository). + - .git/logs/HEAD # This directory includes files that contain the history of the commits. + - .git/refs/heads/ # This directory includes files for each branch that points to the last commit id (local repo). # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware