From ca64652e5fbfc718252a2cfda562fcbf7e27bcb8 Mon Sep 17 00:00:00 2001 From: "S.B" <30941141+s-b-repo@users.noreply.github.com> Date: Sat, 3 Jan 2026 14:20:13 -0500 Subject: [PATCH] Improve error handling in loadOperatingSystems and getIcons Refactor loadOperatingSystems and getIcons functions for better error handling and code clarity. fixes: 1.Wrapped getIcons() in try-catch to handle AssetManifest.json load failures gracefully 2.Added await to getIcons() call for proper async error handling 3.Added try-catch around PackageInfo.fromPlatform() (can also fail with sudo) 4.Uses debugPrint for warnings instead of crashing --- lib/main.dart | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0b5f9ad..3355c1d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,7 +20,6 @@ Future> loadOperatingSystems(bool showUbuntus) async { var process = await Process.run('quickget', ['--list-csv']); var stdout = process.stdout as String; var output = []; - OperatingSystem? currentOperatingSystem; Version? currentVersion; @@ -32,8 +31,7 @@ Future> loadOperatingSystems(bool showUbuntus) async { .forEach((element) { var chunks = element.split(","); Tuple5 supportedVersion; - if (chunks.length == 4) // Legacy version of quickget - { + if (chunks.length == 4) { supportedVersion = Tuple5.fromList([...chunks, "curl"]); } else { var t5 = [chunks[0], chunks[1], chunks[2], chunks[3], chunks[4]].toList(); @@ -46,10 +44,12 @@ Future> loadOperatingSystems(bool showUbuntus) async { output.add(currentOperatingSystem!); currentVersion = null; } + if (currentVersion?.version != supportedVersion.item3) { currentVersion = Version(supportedVersion.item3); currentOperatingSystem!.versions.add(currentVersion!); } + currentVersion!.options .add(Option(supportedVersion.item4, supportedVersion.item5)); }); @@ -58,22 +58,30 @@ Future> loadOperatingSystems(bool showUbuntus) async { } Future getIcons() async { - final manifestContent = await rootBundle.loadString('AssetManifest.json'); - final Map manifestMap = json.decode(manifestContent); - final imagePaths = manifestMap.keys - .where((String key) => key.contains('quickemu-icons/')) - .where((String key) => key.contains('.svg')) - .toList(); - for (final imagePath in imagePaths) { - String filename = imagePath.split('/').last; - String id = filename.substring(0, filename.lastIndexOf('.')); - osIcons[id] = imagePath; + try { + final manifestContent = await rootBundle.loadString('AssetManifest.json'); + final Map manifestMap = json.decode(manifestContent); + final imagePaths = manifestMap.keys + .where((String key) => key.contains('quickemu-icons/')) + .where((String key) => key.contains('.svg')) + .toList(); + + for (final imagePath in imagePaths) { + String filename = imagePath.split('/').last; + String id = filename.substring(0, filename.lastIndexOf('.')); + osIcons[id] = imagePath; + } + } on FlutterError catch (e) { + debugPrint('Warning: Could not load AssetManifest.json: $e'); + // Icons will use fallback/default when not found + } catch (e) { + debugPrint('Warning: Failed to load icons: $e'); } } void main() async { WidgetsFlutterBinding.ensureInitialized(); - // Don't forget to also change the size in linux/my_application.cc:50 + if (Platform.isMacOS) { setWindowMinSize(const Size(692 + 2, 580 + 30)); setWindowMaxSize(const Size(692 + 2, 580 + 30)); @@ -81,12 +89,18 @@ void main() async { setWindowMinSize(const Size(692, 580)); setWindowMaxSize(const Size(800, 720)); } + final foundQuickGet = await Process.run('which', ['quickget']); if (foundQuickGet.exitCode == 0) { gOperatingSystems = loadOperatingSystems(false); - getIcons(); - AppVersion.packageInfo = await PackageInfo.fromPlatform(); + await getIcons(); // Added await for proper error handling + try { + AppVersion.packageInfo = await PackageInfo.fromPlatform(); + } catch (e) { + debugPrint('Warning: Could not get package info: $e'); + } } + runApp( MultiProvider( providers: [