From dcadfb69f500ce4abfa3abb267fbdfa12fabac25 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Mon, 1 Jul 2024 01:18:18 +0100 Subject: [PATCH] feat: add fetchQuickemuVersion() and display version in the menu --- lib/src/globals.dart | 12 ++++++++++++ lib/src/widgets/left_menu.dart | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/src/globals.dart b/lib/src/globals.dart index 3032be2..b20f170 100644 --- a/lib/src/globals.dart +++ b/lib/src/globals.dart @@ -4,3 +4,15 @@ var gIsSnap = Platform.environment['SNAP']?.isNotEmpty ?? false; const String prefWorkingDirectory = 'workingDirectory'; const String prefThemeMode = 'themeMode'; const String prefCurrentLocale = 'currentLocale'; + +Future fetchQuickemuVersion() async { + // Get the version of quickemu + var result = await Process.run('quickemu', ['--version']); + + // If successful return the trimmed version + if (result.exitCode == 0) { + return result.stdout.trim(); + } else { + return ''; + } +} diff --git a/lib/src/widgets/left_menu.dart b/lib/src/widgets/left_menu.dart index 5fa818b..e18a475 100644 --- a/lib/src/widgets/left_menu.dart +++ b/lib/src/widgets/left_menu.dart @@ -22,6 +22,7 @@ class _LeftMenuState extends State with PreferencesMixin { @override void initState() { super.initState(); + fetchQuickemuVersion(); _dropdownMenuItems = supportedLocales .map((e) => DropdownMenuItem(child: Text(e), value: e)) .toList(); @@ -48,9 +49,35 @@ class _LeftMenuState extends State with PreferencesMixin { return Drawer( child: ListView( children: [ - ListTile( - title: Text("Quickgui $_version", - style: const TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold)), + Padding( + // Minimal bottom padding + padding: EdgeInsets.only(bottom: 0).add(EdgeInsets.symmetric(horizontal: 16)), + child: Container( + padding: EdgeInsets.symmetric(vertical: 4.0), + child: Text("Quickgui $_version", + style: const TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold)), + ), + ), + FutureBuilder( + future: fetchQuickemuVersion(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return CircularProgressIndicator(); // or some other widget while waiting + } else { + String poweredByText = context.t('Powered by') + " Quickemu"; + if (snapshot.hasData) { + poweredByText += " ${snapshot.data}"; + } + return Padding( + // Minimal top padding + padding: EdgeInsets.only(top: 0).add(EdgeInsets.symmetric(horizontal: 16)), + child: Container( + child: Text(poweredByText, + style: const TextStyle(fontSize: 12.0, fontWeight: FontWeight.bold)), + ), + ); + } + }, ), Container( height: 4.0,