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>
This commit is contained in:
The one with the braid 2023-11-12 14:58:31 +01:00
parent fbaeb1807f
commit fd35f31cb2
2 changed files with 53 additions and 39 deletions

View file

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

View file

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