From 53d11e99d73eaf48fa8bf1a2c47796485c57c532 Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 18 Oct 2024 08:45:16 +0800 Subject: [PATCH] web only decode the latest image (#9689) 1. web only decode the latest image 2. web/ios remove relay server config when import Signed-off-by: 21pages --- flutter/lib/common.dart | 3 +++ flutter/lib/models/model.dart | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 86f532d2a..8bf8cb056 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -3177,6 +3177,9 @@ importConfig(List? controllers, List? errMsgs, if (text != null && text.isNotEmpty) { try { final sc = ServerConfig.decode(text); + if (isWeb || isIOS) { + sc.relayServer = ''; + } if (sc.idServer.isNotEmpty) { Future success = setServerConfig(controllers, errMsgs, sc); success.then((value) { diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 71effd797..d836f62a6 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -1225,6 +1225,27 @@ class ImageModel with ChangeNotifier { clearImage() => _image = null; + bool _webDecodingRgba = false; + final List _webRgbaList = List.empty(growable: true); + webOnRgba(int display, Uint8List rgba) async { + // deep copy needed, otherwise "instantiateCodec failed: TypeError: Cannot perform Construct on a detached ArrayBuffer" + _webRgbaList.add(Uint8List.fromList(rgba)); + if (_webDecodingRgba) { + return; + } + _webDecodingRgba = true; + try { + while (_webRgbaList.isNotEmpty) { + final rgba2 = _webRgbaList.last; + _webRgbaList.clear(); + await decodeAndUpdate(display, rgba2); + } + } catch (e) { + debugPrint('onRgba error: $e'); + } + _webDecodingRgba = false; + } + onRgba(int display, Uint8List rgba) async { try { await decodeAndUpdate(display, rgba);