π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix Android main thread blocking, localize strings, guard URL launch
Amrithesh Kakkoth Entea74f58cdb9fa
diff --git a/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_qr/EnteQrPlugin.kt b/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_qr/EnteQrPlugin.ktindex 68110ca9be..44f97fa34a 100644--- a/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_qr/EnteQrPlugin.kt+++ b/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_qr/EnteQrPlugin.kt@@ -19,14 +19,12 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandlerimport io.flutter.plugin.common.MethodChannel.Resultimport java.io.Fileimport java.util.*+import java.util.concurrent.Executors/** EnteQrPlugin */class EnteQrPlugin: FlutterPlugin, MethodCallHandler {- /// The MethodChannel that will the communication between Flutter and native Android- ///- /// This local reference serves to register the plugin with the Flutter Engine and unregister it- /// when the Flutter Engine is detached from the Activityprivate lateinit var channel : MethodChannel+ private val executor = Executors.newSingleThreadExecutor()override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {channel = MethodChannel(flutterPluginBinding.binaryMessenger, "ente_qr")@@ -48,14 +46,15 @@ class EnteQrPlugin: FlutterPlugin, MethodCallHandler {return}- try {- val qrResult = scanQrCode(imagePath)- result.success(qrResult)- } catch (e: Exception) {- result.success(mapOf(- "success" to false,- "error" to "Error scanning QR code: ${e.message}"- ))+ executor.execute {+ val qrResult = try {+ scanQrCode(imagePath)+ } catch (e: Exception) {+ mapOf("success" to false, "error" to "Error scanning QR code: ${e.message}")+ }+ android.os.Handler(android.os.Looper.getMainLooper()).post {+ result.success(qrResult)+ }}}"scanAllQrFromImage" -> {@@ -68,14 +67,15 @@ class EnteQrPlugin: FlutterPlugin, MethodCallHandler {return}- try {- val qrResult = scanAllQrCodes(imagePath)- result.success(qrResult)- } catch (e: Exception) {- result.success(mapOf(- "success" to false,- "error" to "Error scanning QR codes: ${e.message}"- ))+ executor.execute {+ val qrResult = try {+ scanAllQrCodes(imagePath)+ } catch (e: Exception) {+ mapOf("success" to false, "error" to "Error scanning QR codes: ${e.message}")+ }+ android.os.Handler(android.os.Looper.getMainLooper()).post {+ result.success(qrResult)+ }}}else -> {@@ -154,26 +154,24 @@ class EnteQrPlugin: FlutterPlugin, MethodCallHandler {}private fun scanAllQrCodes(imagePath: String): Map<String, Any> {- try {- val file = File(imagePath)- if (!file.exists()) {- return mapOf(- "success" to false,- "error" to "Image file not found: $imagePath"- )- }+ val file = File(imagePath)+ if (!file.exists()) {+ return mapOf(+ "success" to false,+ "error" to "Image file not found: $imagePath"+ )+ }- val origBitmap = BitmapFactory.decodeFile(imagePath)- if (origBitmap == null) {- return mapOf(- "success" to false,- "error" to "Unable to decode image file"- )- }+ val origBitmap = BitmapFactory.decodeFile(imagePath)+ ?: return mapOf(+ "success" to false,+ "error" to "Unable to decode image file"+ )+ var bitmap = origBitmap+ try {val origWidth = origBitmap.width.toDouble()val origHeight = origBitmap.height.toDouble()- var bitmap = origBitmapfor (i in 0..2) {if (i != 0) {@@ -265,6 +263,8 @@ class EnteQrPlugin: FlutterPlugin, MethodCallHandler {"error" to "No QR code found in image")} catch (e: Exception) {+ if (bitmap !== origBitmap) bitmap.recycle()+ origBitmap.recycle()return mapOf("success" to false,"error" to "Error scanning QR codes: ${e.message}"diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 2fdf2134a0..9a317cfb56 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -968,6 +968,7 @@"shareLink": "Share link","openLink": "Open link","pay": "Pay",+ "noPaymentAppFound": "No payment app found","createCollage": "Create collage","saveCollage": "Save collage","collageSaved": "Collage saved to gallery",diff --git a/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dart b/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dartindex 0cb6739889..1b6fae93a5 100644--- a/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dart@@ -96,7 +96,9 @@ class _QrContentEntry extends StatelessWidget {buttonType: ButtonTypeV2.primary,labelText: l10n.openLink,onTap: () async {- await launchUrl(uri, mode: LaunchMode.externalApplication);+ try {+ await launchUrl(uri, mode: LaunchMode.externalApplication);+ } catch (_) {}},),const SizedBox(height: 8),@@ -119,11 +121,11 @@ class _QrContentEntry extends StatelessWidget {mode: LaunchMode.externalApplication,);if (!launched && context.mounted) {- showShortToast(context, "No payment app found");+ showShortToast(context, l10n.noPaymentAppFound);}} catch (_) {if (context.mounted) {- showShortToast(context, "No payment app found");+ showShortToast(context, l10n.noPaymentAppFound);}}},