From 9fbe52481850137f5cb812186a6d235b76c347da Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Wed, 22 Mar 2023 22:36:04 -0400 Subject: [PATCH] Bugfix: Infinite load on corrupt App JSON (#378) --- lib/main.dart | 2 +- lib/providers/apps_provider.dart | 16 +++++++++++++++- pubspec.yaml | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 7be4cea..9d7f7ad 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -21,7 +21,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart'; // ignore: implementation_imports import 'package:easy_localization/src/localization.dart'; -const String currentVersion = '0.11.12'; +const String currentVersion = '0.11.13'; const String currentReleaseTag = 'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index dc4f9c0..f3069df 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -571,7 +571,21 @@ class AppsProvider with ChangeNotifier { List newApps = (await getAppsDir()) .listSync() .where((item) => item.path.toLowerCase().endsWith('.json')) - .map((e) => App.fromJson(jsonDecode(File(e.path).readAsStringSync()))) + .map((e) { + try { + return App.fromJson(jsonDecode(File(e.path).readAsStringSync())); + } catch (err) { + if (err is FormatException) { + logs.add('Corrupt JSON when loading App (will be ignored): $e'); + e.renameSync('${e.path}.corrupt'); + return App( + '', '', '', '', '', '', [], 0, {}, DateTime.now(), false); + } else { + rethrow; + } + } + }) + .where((element) => element.id.isNotEmpty) .toList(); var idsToDelete = apps.values .map((e) => e.app.id) diff --git a/pubspec.yaml b/pubspec.yaml index 0a5d632..d546491 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.11.12+133 # When changing this, update the tag in main() accordingly +version: 0.11.13+134 # When changing this, update the tag in main() accordingly environment: sdk: '>=2.18.2 <3.0.0'