From 6e87353e0857e3031060f0748909793faf28e2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Fri, 24 Oct 2025 13:32:59 +0200 Subject: [PATCH] feat: Enable native imaging for web --- .gitignore | 3 ++- lib/utils/client_manager.dart | 3 ++- lib/utils/custom_image_resizer.dart | 6 ------ scripts/prepare-web.sh | 10 +++++++++- web/index.html | 1 + 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 8919199a9..7ed5bfe78 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,8 @@ prime # libolm package -/assets/js/package +web/Imaging.js +web/Imaging.wasm # IntelliJ related *.iml diff --git a/lib/utils/client_manager.dart b/lib/utils/client_manager.dart index 9fe1b2dfd..716abd80c 100644 --- a/lib/utils/client_manager.dart +++ b/lib/utils/client_manager.dart @@ -122,7 +122,8 @@ abstract class ClientManager { AuthenticationTypes.sso, }, nativeImplementations: nativeImplementations, - customImageResizer: PlatformInfos.isMobile ? customImageResizer : null, + customImageResizer: + PlatformInfos.isMobile || kIsWeb ? customImageResizer : null, defaultNetworkRequestTimeout: const Duration(minutes: 30), enableDehydratedDevices: true, shareKeysWith: ShareKeysWith.values diff --git a/lib/utils/custom_image_resizer.dart b/lib/utils/custom_image_resizer.dart index f783d5cac..3431bfc6f 100644 --- a/lib/utils/custom_image_resizer.dart +++ b/lib/utils/custom_image_resizer.dart @@ -18,12 +18,6 @@ import 'package:native_imaging/native_imaging.dart' as native; Future customImageResizer( MatrixImageFileResizeArguments arguments, ) async { - if (kIsWeb) { - throw UnsupportedError( - 'customImageResizer only supports non-web platforms.', - ); - } - await native.init(); var imageBytes = arguments.bytes; diff --git a/scripts/prepare-web.sh b/scripts/prepare-web.sh index 13a26ac09..6ffb59f6e 100755 --- a/scripts/prepare-web.sh +++ b/scripts/prepare-web.sh @@ -9,4 +9,12 @@ flutter_rust_bridge_codegen build-web --dart-root dart --rust-root $(readlink -f cd .. rm -f ./assets/vodozemac/vodozemac_bindings_dart* mv .vodozemac/dart/web/pkg/vodozemac_bindings_dart* ./assets/vodozemac/ -rm -rf .vodozemac \ No newline at end of file +rm -rf .vodozemac + +# Add native imaging: +cd web/ +curl -L 'https://github.com/famedly/dart_native_imaging/releases/download/v0.2.1/native_imaging.zip' > native_imaging.zip # make sure to sync version with pubspec.yaml +unzip native_imaging.zip +mv js/* . +rmdir js +rm native_imaging.zip \ No newline at end of file diff --git a/web/index.html b/web/index.html index 5962ecdba..c593cc057 100644 --- a/web/index.html +++ b/web/index.html @@ -33,6 +33,7 @@ FluffyChat +