fix: emoji import from ZIP file

- fix invalid Navigator scope in Emoji import dialog
- add progress bar to Emoji import dialog

Fixes: #623

Signed-off-by: The one with the braid <info@braid.business>
pull/673/head
The one with the braid 2 years ago
parent fbaeb1807f
commit fd35f31cb2

@ -33,6 +33,8 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
bool _loading = false; bool _loading = false;
double _progress = 0;
@override @override
void initState() { void initState() {
_importFileMap(); _importFileMap();
@ -44,7 +46,11 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
return AlertDialog( return AlertDialog(
title: Text(L10n.of(context)!.importEmojis), title: Text(L10n.of(context)!.importEmojis),
content: _loading content: _loading
? const Center(child: CircularProgressIndicator()) ? Center(
child: CircularProgressIndicator(
value: _progress,
),
)
: SingleChildScrollView( : SingleChildScrollView(
child: Wrap( child: Wrap(
alignment: WrapAlignment.spaceEvenly, alignment: WrapAlignment.spaceEvenly,
@ -97,6 +103,7 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
Future<void> _addEmotePack() async { Future<void> _addEmotePack() async {
setState(() { setState(() {
_loading = true; _loading = true;
_progress = 0;
}); });
final imports = _importMap; final imports = _importMap;
final successfulUploads = <String>{}; final successfulUploads = <String>{};
@ -134,20 +141,25 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
} }
for (final entry in imports.entries) { for (final entry in imports.entries) {
setState(() {
_progress += 1 / imports.length;
});
final file = entry.key; final file = entry.key;
final imageCode = entry.value; final imageCode = entry.value;
// try { try {
var mxcFile = MatrixImageFile( var mxcFile = MatrixImageFile(
bytes: file.content, bytes: file.content,
name: file.name, name: file.name,
); );
try {
mxcFile = (await mxcFile.generateThumbnail( final thumbnail = (await mxcFile.generateThumbnail(
nativeImplementations: ClientManager.nativeImplementations, nativeImplementations: ClientManager.nativeImplementations,
))!; ));
} catch (e, s) { if (thumbnail == null) {
Logs().w('Unable to create thumbnail', e, s); Logs().w('Unable to create thumbnail');
} else {
mxcFile = thumbnail;
} }
final uri = await Matrix.of(context).client.uploadContent( final uri = await Matrix.of(context).client.uploadContent(
mxcFile.bytes, mxcFile.bytes,
@ -176,10 +188,9 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
'info': info, 'info': info,
}); });
successfulUploads.add(file.name); successfulUploads.add(file.name);
/*} catch (e) { } catch (e) {
Logs().d('Could not upload emote $imageCode'); Logs().d('Could not upload emote $imageCode');
}*/ }
} }
await widget.controller.save(context); await widget.controller.save(context);
@ -188,6 +199,7 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
); );
_loading = false; _loading = false;
_progress = 0;
// in case we have unhandled / duplicated emotes left, don't pop // in case we have unhandled / duplicated emotes left, don't pop
if (mounted) setState(() {}); if (mounted) setState(() {});

@ -309,6 +309,8 @@ class EmotesSettingsController extends State<EmotesSettings> {
await showDialog( await showDialog(
context: context, context: context,
// breaks [Matrix.of] calls otherwise
useRootNavigator: false,
builder: (context) => ImportEmoteArchiveDialog( builder: (context) => ImportEmoteArchiveDialog(
controller: this, controller: this,
archive: archive, archive: archive,

Loading…
Cancel
Save