diff --git a/lib/pages/settings_emotes/import_archive_dialog.dart b/lib/pages/settings_emotes/import_archive_dialog.dart index fd25fc9c..0ed5bb21 100644 --- a/lib/pages/settings_emotes/import_archive_dialog.dart +++ b/lib/pages/settings_emotes/import_archive_dialog.dart @@ -33,6 +33,8 @@ class _ImportEmoteArchiveDialogState extends State { bool _loading = false; + double _progress = 0; + @override void initState() { _importFileMap(); @@ -44,7 +46,11 @@ class _ImportEmoteArchiveDialogState extends State { return AlertDialog( title: Text(L10n.of(context)!.importEmojis), content: _loading - ? const Center(child: CircularProgressIndicator()) + ? Center( + child: CircularProgressIndicator( + value: _progress, + ), + ) : SingleChildScrollView( child: Wrap( alignment: WrapAlignment.spaceEvenly, @@ -97,6 +103,7 @@ class _ImportEmoteArchiveDialogState extends State { Future _addEmotePack() async { setState(() { _loading = true; + _progress = 0; }); final imports = _importMap; final successfulUploads = {}; @@ -134,52 +141,56 @@ class _ImportEmoteArchiveDialogState extends State { } for (final entry in imports.entries) { + setState(() { + _progress += 1 / imports.length; + }); final file = entry.key; final imageCode = entry.value; - // try { - var mxcFile = MatrixImageFile( - bytes: file.content, - name: file.name, - ); try { - mxcFile = (await mxcFile.generateThumbnail( + var mxcFile = MatrixImageFile( + bytes: file.content, + name: file.name, + ); + + final thumbnail = (await mxcFile.generateThumbnail( nativeImplementations: ClientManager.nativeImplementations, - ))!; - } catch (e, s) { - Logs().w('Unable to create thumbnail', e, s); - } - final uri = await Matrix.of(context).client.uploadContent( - mxcFile.bytes, - filename: mxcFile.name, - contentType: mxcFile.mimeType, - ); - - final info = { - ...mxcFile.info, - }; - - // normalize width / height to 256, required for stickers - if (info['w'] is int && info['h'] is int) { - final ratio = info['w'] / info['h']; - if (info['w'] > info['h']) { - info['w'] = 256; - info['h'] = (256.0 / ratio).round(); + )); + if (thumbnail == null) { + Logs().w('Unable to create thumbnail'); } else { - info['h'] = 256; - info['w'] = (ratio * 256.0).round(); + mxcFile = thumbnail; } - } - widget.controller.pack!.images[imageCode] = - ImagePackImageContent.fromJson({ - 'url': uri.toString(), - 'info': info, - }); - successfulUploads.add(file.name); - /*} catch (e) { + final uri = await Matrix.of(context).client.uploadContent( + mxcFile.bytes, + filename: mxcFile.name, + contentType: mxcFile.mimeType, + ); - Logs().d('Could not upload emote $imageCode'); - }*/ + final info = { + ...mxcFile.info, + }; + + // normalize width / height to 256, required for stickers + if (info['w'] is int && info['h'] is int) { + final ratio = info['w'] / info['h']; + if (info['w'] > info['h']) { + info['w'] = 256; + info['h'] = (256.0 / ratio).round(); + } else { + info['h'] = 256; + info['w'] = (ratio * 256.0).round(); + } + } + widget.controller.pack!.images[imageCode] = + ImagePackImageContent.fromJson({ + 'url': uri.toString(), + 'info': info, + }); + successfulUploads.add(file.name); + } catch (e) { + Logs().d('Could not upload emote $imageCode'); + } } await widget.controller.save(context); @@ -188,6 +199,7 @@ class _ImportEmoteArchiveDialogState extends State { ); _loading = false; + _progress = 0; // in case we have unhandled / duplicated emotes left, don't pop if (mounted) setState(() {}); diff --git a/lib/pages/settings_emotes/settings_emotes.dart b/lib/pages/settings_emotes/settings_emotes.dart index 92f2d7ea..2ef905b1 100644 --- a/lib/pages/settings_emotes/settings_emotes.dart +++ b/lib/pages/settings_emotes/settings_emotes.dart @@ -309,6 +309,8 @@ class EmotesSettingsController extends State { await showDialog( context: context, + // breaks [Matrix.of] calls otherwise + useRootNavigator: false, builder: (context) => ImportEmoteArchiveDialog( controller: this, archive: archive,