Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[auth] add top-level error handling back to icon utils

Prateek Sunal7430b4f05819
diff --git a/mobile/apps/auth/lib/ui/utils/icon_utils.dart b/mobile/apps/auth/lib/ui/utils/icon_utils.dart
index c495cc5345..78fe597c50 100644
--- a/mobile/apps/auth/lib/ui/utils/icon_utils.dart
+++ b/mobile/apps/auth/lib/ui/utils/icon_utils.dart
@@ -26,20 +26,54 @@ class IconUtils {
}
Map<String, AllIconData> getAllIcons() {
- Set<String> processedIconPaths = {};
- final allIcons = <String, AllIconData>{};
+ try {
+ Set<String> processedIconPaths = {};
+ final allIcons = <String, AllIconData>{};
+
+ final simpleIterator = _simpleIcons.entries.iterator;
+ final customIterator = _customIcons.entries.iterator;
+
+ var simpleEntry =
+ simpleIterator.moveNext() ? simpleIterator.current : null;
+ var customEntry =
+ customIterator.moveNext() ? customIterator.current : null;
- final simpleIterator = _simpleIcons.entries.iterator;
- final customIterator = _customIcons.entries.iterator;
+ String simpleIconPath, customIconPath;
- var simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
- var customEntry = customIterator.moveNext() ? customIterator.current : null;
+ while (simpleEntry != null && customEntry != null) {
+ if (simpleEntry.key.compareTo(customEntry.key) <= 0) {
+ simpleIconPath =
+ "assets/simple-icons/icons/${simpleEntry.key}.svg";
+ if (!processedIconPaths.contains(simpleIconPath)) {
+ allIcons[simpleEntry.key] = AllIconData(
+ title: simpleEntry.key,
+ type: IconType.simpleIcon,
+ color: simpleEntry.value,
+ );
+ processedIconPaths.add(simpleIconPath);
+ }
+ simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
+ } else {
+ customIconPath =
+ "assets/custom-icons/icons/${customEntry.value.slug ?? customEntry.key}.svg";
- String simpleIconPath, customIconPath;
+ if (!processedIconPaths.contains(customIconPath)) {
+ allIcons[customEntry.key] = AllIconData(
+ title: customEntry.key,
+ type: IconType.customIcon,
+ color: customEntry.value.color,
+ slug: customEntry.value.slug,
+ );
+ processedIconPaths.add(customIconPath);
+ }
+ customEntry =
+ customIterator.moveNext() ? customIterator.current : null;
+ }
+ }
- while (simpleEntry != null && customEntry != null) {
- if (simpleEntry.key.compareTo(customEntry.key) <= 0) {
+ while (simpleEntry != null) {
simpleIconPath = "assets/simple-icons/icons/${simpleEntry.key}.svg";
+
if (!processedIconPaths.contains(simpleIconPath)) {
allIcons[simpleEntry.key] = AllIconData(
title: simpleEntry.key,
@@ -49,7 +83,9 @@ class IconUtils {
processedIconPaths.add(simpleIconPath);
}
simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
- } else {
+ }
+
+ while (customEntry != null) {
customIconPath =
"assets/custom-icons/icons/${customEntry.value.slug ?? customEntry.key}.svg";
@@ -64,39 +100,12 @@ class IconUtils {
}
customEntry = customIterator.moveNext() ? customIterator.current : null;
}
- }
-
- while (simpleEntry != null) {
- simpleIconPath = "assets/simple-icons/icons/${simpleEntry.key}.svg";
-
- if (!processedIconPaths.contains(simpleIconPath)) {
- allIcons[simpleEntry.key] = AllIconData(
- title: simpleEntry.key,
- type: IconType.simpleIcon,
- color: simpleEntry.value,
- );
- processedIconPaths.add(simpleIconPath);
- }
- simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
- }
-
- while (customEntry != null) {
- customIconPath =
- "assets/custom-icons/icons/${customEntry.value.slug ?? customEntry.key}.svg";
- if (!processedIconPaths.contains(customIconPath)) {
- allIcons[customEntry.key] = AllIconData(
- title: customEntry.key,
- type: IconType.customIcon,
- color: customEntry.value.color,
- slug: customEntry.value.slug,
- );
- processedIconPaths.add(customIconPath);
- }
- customEntry = customIterator.moveNext() ? customIterator.current : null;
+ return allIcons;
+ } catch (e, s) {
+ Logger("IconUtils").severe("Failed to get all icons", e, s);
+ return {};
}
-
- return allIcons;
}
Widget getIcon(
@@ -104,37 +113,46 @@ class IconUtils {
String provider, {
double width = 24,
}) {
- final providerTitle = _getProviderTitle(provider);
- final List<String> titlesList = [providerTitle];
- titlesList.addAll(
- _titleSplitCharacters
- .where((char) => providerTitle.contains(char))
- .map((char) => providerTitle.split(char)[0]),
- );
- for (final title in titlesList) {
- if (_customIcons.containsKey(title)) {
- return getSVGIcon(
- "assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg",
- title,
- _customIcons[title]!.color,
- width,
- context,
- );
- } else if (_simpleIcons.containsKey(title)) {
- final simpleIconPath = normalizeSimpleIconName(title);
- return getSVGIcon(
- "assets/simple-icons/icons/$simpleIconPath.svg",
- title,
- _simpleIcons[title],
- width,
- context,
- );
+ try {
+ final providerTitle = _getProviderTitle(provider);
+ final List<String> titlesList = [providerTitle];
+ titlesList.addAll(
+ _titleSplitCharacters
+ .where((char) => providerTitle.contains(char))
+ .map((char) => providerTitle.split(char)[0]),
+ );
+ for (final title in titlesList) {
+ if (_customIcons.containsKey(title)) {
+ return getSVGIcon(
+ "assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg",
+ title,
+ _customIcons[title]!.color,
+ width,
+ context,
+ );
+ } else if (_simpleIcons.containsKey(title)) {
+ final simpleIconPath = normalizeSimpleIconName(title);
+ return getSVGIcon(
+ "assets/simple-icons/icons/$simpleIconPath.svg",
+ title,
+ _simpleIcons[title],
+ width,
+ context,
+ );
+ }
}
- }
- if (providerTitle.isNotEmpty) {
+ if (providerTitle.isNotEmpty) {
+ return _fallbackAvatar(provider, width, context);
+ } else {
+ return const SizedBox.shrink();
+ }
+ } catch (e, s) {
+ Logger("IconUtils").warning(
+ "Failed to get icon for provider '$provider'",
+ e,
+ s,
+ );
return _fallbackAvatar(provider, width, context);
- } else {
- return const SizedBox.shrink();
}
}