Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move QR decoder plugin to shared package

Neeraj Guptaed3e8f6e6ecb
diff --git a/mobile/apps/auth/android/build.gradle b/mobile/apps/auth/android/build.gradle
index b3c47285d6..c96283dcaf 100644
--- a/mobile/apps/auth/android/build.gradle
+++ b/mobile/apps/auth/android/build.gradle
@@ -2,6 +2,7 @@ allprojects {
repositories {
google()
mavenCentral()
+ maven { url 'https://jitpack.io' }
}
}
diff --git a/mobile/apps/auth/ios/Podfile.lock b/mobile/apps/auth/ios/Podfile.lock
index 5da08e3c27..84c3507f5f 100644
--- a/mobile/apps/auth/ios/Podfile.lock
+++ b/mobile/apps/auth/ios/Podfile.lock
@@ -41,7 +41,7 @@ PODS:
- DKPhotoGallery/Resource (0.0.19):
- SDWebImage
- SwiftyGif
- - ente_auth_qr (0.0.1):
+ - ente_qr (0.0.1):
- Flutter
- file_picker (0.0.1):
- DKImagePickerController/PhotoGallery
@@ -130,7 +130,7 @@ DEPENDENCIES:
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- cupertino_http (from `.symlinks/plugins/cupertino_http/darwin`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- - ente_auth_qr (from `.symlinks/plugins/ente_auth_qr/ios`)
+ - ente_qr (from `.symlinks/plugins/ente_qr/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- file_saver (from `.symlinks/plugins/file_saver/ios`)
- Flutter (from `Flutter`)
@@ -175,8 +175,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/cupertino_http/darwin"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
- ente_auth_qr:
- :path: ".symlinks/plugins/ente_auth_qr/ios"
+ ente_qr:
+ :path: ".symlinks/plugins/ente_qr/ios"
file_picker:
:path: ".symlinks/plugins/file_picker/ios"
file_saver:
@@ -232,7 +232,7 @@ SPEC CHECKSUMS:
device_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbe
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
- ente_auth_qr: f79ccafca07144447980c66c66d3cf28f4eda82d
+ ente_qr: 86beaf5d2644705db9b565b32dd8b82c05fb36af
file_picker: a0560bc09d61de87f12d246fc47d2119e6ef37be
file_saver: 6cdbcddd690cb02b0c1a0c225b37cd805c2bf8b6
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
diff --git a/mobile/apps/auth/lib/utils/gallery_import_util.dart b/mobile/apps/auth/lib/utils/gallery_import_util.dart
index f70a970e52..1688d9eb8c 100644
--- a/mobile/apps/auth/lib/utils/gallery_import_util.dart
+++ b/mobile/apps/auth/lib/utils/gallery_import_util.dart
@@ -4,7 +4,7 @@ import 'package:backup_exclusion/backup_exclusion.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/utils/dialog_util.dart';
-import 'package:ente_auth_qr/ente_qr.dart';
+import 'package:ente_qr/ente_qr.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
diff --git a/mobile/apps/auth/macos/Flutter/GeneratedPluginRegistrant.swift b/mobile/apps/auth/macos/Flutter/GeneratedPluginRegistrant.swift
index baf45d8c49..90d7e31964 100644
--- a/mobile/apps/auth/macos/Flutter/GeneratedPluginRegistrant.swift
+++ b/mobile/apps/auth/macos/Flutter/GeneratedPluginRegistrant.swift
@@ -8,6 +8,7 @@ import Foundation
import app_links
import connectivity_plus
import device_info_plus
+import ente_qr
import file_picker
import file_saver
import flutter_local_notifications
@@ -30,6 +31,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
+ EnteQrPlugin.register(with: registry.registrar(forPlugin: "EnteQrPlugin"))
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
diff --git a/mobile/apps/auth/macos/Podfile.lock b/mobile/apps/auth/macos/Podfile.lock
index 5ca73cceb0..5cb9253ba8 100644
--- a/mobile/apps/auth/macos/Podfile.lock
+++ b/mobile/apps/auth/macos/Podfile.lock
@@ -8,6 +8,8 @@ PODS:
- FlutterMacOS
- device_info_plus (0.0.1):
- FlutterMacOS
+ - ente_qr (0.0.1):
+ - FlutterMacOS
- file_picker (0.0.1):
- FlutterMacOS
- file_saver (0.0.1):
@@ -79,6 +81,7 @@ DEPENDENCIES:
- connectivity_plus (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus/macos`)
- cupertino_http (from `Flutter/ephemeral/.symlinks/plugins/cupertino_http/darwin`)
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
+ - ente_qr (from `Flutter/ephemeral/.symlinks/plugins/ente_qr/macos`)
- file_picker (from `Flutter/ephemeral/.symlinks/plugins/file_picker/macos`)
- file_saver (from `Flutter/ephemeral/.symlinks/plugins/file_saver/macos`)
- flutter_local_notifications (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos`)
@@ -112,6 +115,8 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/cupertino_http/darwin
device_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos
+ ente_qr:
+ :path: Flutter/ephemeral/.symlinks/plugins/ente_qr/macos
file_picker:
:path: Flutter/ephemeral/.symlinks/plugins/file_picker/macos
file_saver:
@@ -154,6 +159,7 @@ SPEC CHECKSUMS:
connectivity_plus: 4adf20a405e25b42b9c9f87feff8f4b6fde18a4e
cupertino_http: 94ac07f5ff090b8effa6c5e2c47871d48ab7c86c
device_info_plus: 4fb280989f669696856f8b129e4a5e3cd6c48f76
+ ente_qr: 679dcacb6a07788ee2e79d29485b07064cdec78d
file_picker: 7584aae6fa07a041af2b36a2655122d42f578c1a
file_saver: e35bd97de451dde55ff8c38862ed7ad0f3418d0f
flutter_local_notifications: 13862b132e32eb858dea558a86d45d08daeacfe7
diff --git a/mobile/apps/auth/plugins/qr/CHANGELOG.md b/mobile/apps/auth/plugins/qr/CHANGELOG.md
deleted file mode 100644
index 7104fdcae1..0000000000
--- a/mobile/apps/auth/plugins/qr/CHANGELOG.md
+++ /dev/null
@@ -1,8 +0,0 @@
-## 0.0.1
-
-- Initial release of ente_auth_qr plugin
-- Support for scanning QR codes from image files
-- Android implementation using ZXing library
-- iOS implementation using Core Image framework
-- Comprehensive error handling
-- Example app demonstrating usage with file picker
diff --git a/mobile/apps/auth/plugins/qr/README.md b/mobile/apps/auth/plugins/qr/README.md
deleted file mode 100644
index 56f5733b08..0000000000
--- a/mobile/apps/auth/plugins/qr/README.md
+++ /dev/null
@@ -1,176 +0,0 @@
-# ente_auth_qr
-
-A Flutter plugin for scanning QR codes from image files. This plugin provides a simple interface to scan QR codes from images on both Android and iOS platforms.
-
-## Features
-
-- Scan QR codes from image files
-- Support for Android (using ZXing library)
-- Support for iOS (using AVFoundation/Core Image)
-- Returns structured results with error handling
-- Works with images from file picker or camera
-
-## Platform Support
-
-| Platform | Support |
-| -------- | ------- |
-| Android | βœ… |
-| iOS | βœ… |
-| Web | ❌ |
-| macOS | ❌ |
-| Windows | ❌ |
-| Linux | ❌ |
-
-## Installation
-
-Add this to your package's `pubspec.yaml` file:
-
-```yaml
-dependencies:
- ente_auth_qr:
- path: path/to/ente_auth_qr
-```
-
-## Usage
-
-### Basic Usage
-
-```dart
-import 'package:ente_auth_qr/ente_qr.dart';
-
-final qr = EnteQr();
-
-// Scan QR code from an image file
-final result = await qr.scanQrFromImage('/path/to/image.jpg');
-
-if (result.success) {
- print('QR Code content: ${result.content}');
-} else {
- print('Error: ${result.error}');
-}
-```
-
-### Complete Example with File Picker
-
-```dart
-import 'package:flutter/material.dart';
-import 'package:ente_auth_qr/ente_qr.dart';
-import 'package:file_picker/file_picker.dart';
-
-class QrScannerPage extends StatefulWidget {
- @override
- _QrScannerPageState createState() => _QrScannerPageState();
-}
-
-class _QrScannerPageState extends State<QrScannerPage> {
- final _enteQr = EnteQr();
- String _result = 'No QR code scanned';
-
- Future<void> _scanQrFromImage() async {
- // Pick an image file
- FilePickerResult? fileResult = await FilePicker.platform.pickFiles(
- type: FileType.image,
- allowMultiple: false,
- );
-
- if (fileResult != null && fileResult.files.single.path != null) {
- final imagePath = fileResult.files.single.path!;
-
- // Scan QR code from the selected image
- final qrResult = await _enteQr.scanQrFromImage(imagePath);
-
- setState(() {
- if (qrResult.success) {
- _result = 'QR Code: ${qrResult.content}';
- } else {
- _result = 'Error: ${qrResult.error}';
- }
- });
- }
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(title: Text('QR Scanner')),
- body: Column(
- children: [
- ElevatedButton(
- onPressed: _scanQrFromImage,
- child: Text('Pick Image and Scan QR'),
- ),
- Text(_result),
- ],
- ),
- );
- }
-}
-```
-
-## API Reference
-
-### EnteQr
-
-The main class for QR code scanning operations.
-
-#### Methods
-
-##### `scanQrFromImage(String imagePath)`
-
-Scans a QR code from an image file.
-
-**Parameters:**
-
-- `imagePath` (String): The file path to the image containing the QR code
-
-**Returns:**
-
-- `Future<QrScanResult>`: A result object containing either the QR code content or an error
-
-### QrScanResult
-
-The result object returned by QR scanning operations.
-
-**Properties:**
-
-- `content` (String?): The QR code content if successful, null otherwise
-- `error` (String?): Error message if scanning failed, null otherwise
-- `success` (bool): Whether the scanning operation was successful
-
-**Factory Constructors:**
-
-- `QrScanResult.success(String content)`: Creates a successful result
-- `QrScanResult.error(String error)`: Creates an error result
-
-## Implementation Details
-
-### Android
-
-The Android implementation uses the ZXing library (com.google.zxing) for QR code detection:
-
-- `com.journeyapps:zxing-android-embedded:4.3.0`
-- `com.google.zxing:core:3.5.1`
-
-### iOS
-
-The iOS implementation uses Core Image framework's built-in QR code detection capabilities via `CIDetector`.
-
-## Error Handling
-
-The plugin provides comprehensive error handling for common scenarios:
-
-- File not found
-- Invalid image format
-- No QR code found in image
-- Platform-specific errors
-- Unexpected errors
-
-All errors are returned as part of the `QrScanResult` object with descriptive error messages.
-
-## Contributing
-
-Contributions are welcome! Please feel free to submit a Pull Request.
-
-## License
-
-This project is licensed under the same license as the Ente project.
diff --git a/mobile/apps/auth/plugins/qr/android/build.gradle b/mobile/apps/auth/plugins/qr/android/build.gradle
deleted file mode 100644
index 63ee95e906..0000000000
--- a/mobile/apps/auth/plugins/qr/android/build.gradle
+++ /dev/null
@@ -1,66 +0,0 @@
-group 'io.ente.auth.ente_auth_qr'
-version '1.0-SNAPSHOT'
-
-buildscript {
- ext.kotlin_version = '1.7.10'
- repositories {
- google()
- mavenCentral()
- }
-
- dependencies {
- classpath 'com.android.tools.build:gradle:7.3.0'
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- }
-}
-
-rootProject.allprojects {
- repositories {
- google()
- mavenCentral()
- }
-}
-
-apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android'
-
-android {
- namespace 'io.ente.auth.ente_auth_qr'
- compileSdk 36
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
-
- kotlinOptions {
- jvmTarget = '1.8'
- }
-
- sourceSets {
- main.java.srcDirs += 'src/main/kotlin'
- test.java.srcDirs += 'src/test/kotlin'
- }
-
- defaultConfig {
- minSdkVersion 16
- }
-
- dependencies {
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
- implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
- implementation 'com.google.zxing:core:3.5.1'
- }
-
- testOptions {
- unitTests.all {
- useJUnitPlatform()
-
- testLogging {
- events "passed", "skipped", "failed", "standardOut", "standardError"
- outputs.upToDateWhen {false}
- showStandardStreams = true
- }
- }
- }
-}
diff --git a/mobile/apps/auth/plugins/qr/android/settings.gradle b/mobile/apps/auth/plugins/qr/android/settings.gradle
deleted file mode 100644
index e8a2f2d279..0000000000
--- a/mobile/apps/auth/plugins/qr/android/settings.gradle
+++ /dev/null
@@ -1 +0,0 @@
-rootProject.name = 'ente_auth_qr'
diff --git a/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_auth_qr/EnteQrPlugin.kt b/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_auth_qr/EnteQrPlugin.kt
deleted file mode 100644
index d39acc0354..0000000000
--- a/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_auth_qr/EnteQrPlugin.kt
+++ /dev/null
@@ -1,278 +0,0 @@
-package io.ente.auth.ente_auth_qr
-
-import android.graphics.Bitmap
-import android.graphics.BitmapFactory
-import androidx.annotation.NonNull
-import com.google.zxing.BarcodeFormat
-import com.google.zxing.BinaryBitmap
-import com.google.zxing.DecodeHintType
-import com.google.zxing.MultiFormatReader
-import com.google.zxing.NotFoundException
-import com.google.zxing.RGBLuminanceSource
-import com.google.zxing.Result as ZXingResult
-import com.google.zxing.common.HybridBinarizer
-import com.google.zxing.multi.GenericMultipleBarcodeReader
-import io.flutter.embedding.engine.plugins.FlutterPlugin
-import io.flutter.plugin.common.MethodCall
-import io.flutter.plugin.common.MethodChannel
-import io.flutter.plugin.common.MethodChannel.MethodCallHandler
-import io.flutter.plugin.common.MethodChannel.Result
-import java.io.File
-import java.util.*
-import java.util.concurrent.Executors
-
-/** EnteQrPlugin */
-class EnteQrPlugin: FlutterPlugin, MethodCallHandler {
- private lateinit var channel : MethodChannel
- private val executor = Executors.newSingleThreadExecutor()
-
- override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
- channel = MethodChannel(flutterPluginBinding.binaryMessenger, "ente_qr")
- channel.setMethodCallHandler(this)
- }
-
- override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
- when (call.method) {
- "getPlatformVersion" -> {
- result.success("Android ${android.os.Build.VERSION.RELEASE}")
- }
- "scanQrFromImage" -> {
- val imagePath = call.argument<String>("imagePath")
- if (imagePath == null) {
- result.success(mapOf(
- "success" to false,
- "error" to "Image path is required"
- ))
- return
- }
-
- 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" -> {
- val imagePath = call.argument<String>("imagePath")
- if (imagePath == null) {
- result.success(mapOf(
- "success" to false,
- "error" to "Image path is required"
- ))
- return
- }
-
- 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 -> {
- result.notImplemented()
- }
- }
- }
-
- private fun scanQrCode(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"
- )
- }
-
- var bitmap = BitmapFactory.decodeFile(imagePath)
- if (bitmap == null) {
- return mapOf(
- "success" to false,
- "error" to "Unable to decode image file"
- )
- }
-
- // Try multiple times with different image sizes like Aegis does
- for (i in 0..2) {
- if (i != 0) {
- // Resize bitmap for subsequent attempts
- val newWidth = bitmap.width / (i * 2)
- val newHeight = bitmap.height / (i * 2)
- if (newWidth > 0 && newHeight > 0) {
- bitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true)
- }
- }
-
- try {
- val width = bitmap.width
- val height = bitmap.height
- val pixels = IntArray(width * height)
- bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
-
- val source = RGBLuminanceSource(width, height, pixels)
- val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
-
- val reader = MultiFormatReader()
- val hints = HashMap<DecodeHintType, Any>()
- hints[DecodeHintType.POSSIBLE_FORMATS] = listOf(BarcodeFormat.QR_CODE)
- hints[DecodeHintType.TRY_HARDER] = true
- hints[DecodeHintType.ALSO_INVERTED] = true
- reader.setHints(hints)
-
- val qrResult: ZXingResult = reader.decode(binaryBitmap)
-
- return mapOf(
- "success" to true,
- "content" to qrResult.text
- )
- } catch (e: NotFoundException) {
- // Continue to next iteration
- continue
- }
- }
-
- return mapOf(
- "success" to false,
- "error" to "No QR code found in image"
- )
- } catch (e: Exception) {
- return mapOf(
- "success" to false,
- "error" to "Error scanning QR code: ${e.message}"
- )
- }
- }
-
- private fun scanAllQrCodes(imagePath: String): Map<String, Any> {
- val file = File(imagePath)
- if (!file.exists()) {
- return mapOf(
- "success" to false,
- "error" to "Image file not found: $imagePath"
- )
- }
-
- 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()
-
- for (i in 0..2) {
- if (i != 0) {
- val newWidth = origBitmap.width / (i * 2)
- val newHeight = origBitmap.height / (i * 2)
- if (newWidth > 0 && newHeight > 0) {
- if (bitmap !== origBitmap) bitmap.recycle()
- bitmap = Bitmap.createScaledBitmap(origBitmap, newWidth, newHeight, true)
- }
- }
-
- try {
- val width = bitmap.width
- val height = bitmap.height
- val pixels = IntArray(width * height)
- bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
-
- val source = RGBLuminanceSource(width, height, pixels)
- val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
-
- val reader = MultiFormatReader()
- val hints = HashMap<DecodeHintType, Any>()
- hints[DecodeHintType.POSSIBLE_FORMATS] = listOf(BarcodeFormat.QR_CODE)
- hints[DecodeHintType.TRY_HARDER] = true
- hints[DecodeHintType.ALSO_INVERTED] = true
- reader.setHints(hints)
-
- val multiReader = GenericMultipleBarcodeReader(reader)
- val results: Array<ZXingResult> = multiReader.decodeMultiple(binaryBitmap, hints)
-
- val detections = mutableListOf<Map<String, Any>>()
- val scaleX = if (i == 0) 1.0 else (i * 2).toDouble()
- val scaleY = if (i == 0) 1.0 else (i * 2).toDouble()
-
- for (qrResult in results) {
- val points = qrResult.resultPoints
- if (points == null || points.isEmpty()) continue
-
- var minX = Float.MAX_VALUE
- var minY = Float.MAX_VALUE
- var maxX = -Float.MAX_VALUE
- var maxY = -Float.MAX_VALUE
-
- for (point in points) {
- if (point == null) continue
- val px = point.x * scaleX.toFloat()
- val py = point.y * scaleY.toFloat()
- if (px < minX) minX = px
- if (py < minY) minY = py
- if (px > maxX) maxX = px
- if (py > maxY) maxY = py
- }
-
- // Add padding around finder patterns (they mark corners, not edges)
- val padX = (maxX - minX) * 0.15f
- val padY = (maxY - minY) * 0.15f
- minX = (minX - padX).coerceAtLeast(0f)
- minY = (minY - padY).coerceAtLeast(0f)
- maxX = (maxX + padX).coerceAtMost(origWidth.toFloat())
- maxY = (maxY + padY).coerceAtMost(origHeight.toFloat())
-
- detections.add(mapOf(
- "content" to qrResult.text,
- "x" to (minX / origWidth),
- "y" to (minY / origHeight),
- "width" to ((maxX - minX) / origWidth),
- "height" to ((maxY - minY) / origHeight),
- ))
- }
-
- if (detections.isNotEmpty()) {
- if (bitmap !== origBitmap) bitmap.recycle()
- origBitmap.recycle()
- return mapOf(
- "success" to true,
- "detections" to detections
- )
- }
- } catch (e: NotFoundException) {
- continue
- }
- }
-
- if (bitmap !== origBitmap) bitmap.recycle()
- origBitmap.recycle()
-
- return mapOf(
- "success" to false,
- "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}"
- )
- }
- }
-
- override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
- channel.setMethodCallHandler(null)
- }
-}
diff --git a/mobile/apps/auth/plugins/qr/ios/Classes/EnteQrPlugin.swift b/mobile/apps/auth/plugins/qr/ios/Classes/EnteQrPlugin.swift
deleted file mode 100644
index f7c656fffd..0000000000
--- a/mobile/apps/auth/plugins/qr/ios/Classes/EnteQrPlugin.swift
+++ /dev/null
@@ -1,200 +0,0 @@
-import Flutter
-import UIKit
-
-public class EnteQrPlugin: NSObject, FlutterPlugin {
- private static let detectionQueue = DispatchQueue(label: "io.ente.qr.detection", qos: .userInitiated)
-
- public static func register(with registrar: FlutterPluginRegistrar) {
- let channel = FlutterMethodChannel(name: "ente_qr", binaryMessenger: registrar.messenger())
- let instance = EnteQrPlugin()
- registrar.addMethodCallDelegate(instance, channel: channel)
- }
-
- public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
- switch call.method {
- case "getPlatformVersion":
- result("iOS " + UIDevice.current.systemVersion)
- case "scanQrFromImage":
- guard let args = call.arguments as? [String: Any],
- let imagePath = args["imagePath"] as? String else {
- result([
- "success": false,
- "error": "Image path is required"
- ])
- return
- }
-
- scanQrCode(from: imagePath, result: result)
- case "scanAllQrFromImage":
- guard let args = call.arguments as? [String: Any],
- let imagePath = args["imagePath"] as? String else {
- result([
- "success": false,
- "error": "Image path is required"
- ])
- return
- }
-
- scanAllQrCodes(from: imagePath, result: result)
- default:
- result(FlutterMethodNotImplemented)
- }
- }
-
- private func scanQrCode(from imagePath: String, result: @escaping FlutterResult) {
- EnteQrPlugin.detectionQueue.async {
- guard let image = UIImage(contentsOfFile: imagePath) else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "Unable to load image from path: \(imagePath)"
- ])
- }
- return
- }
-
- guard let cgImage = image.cgImage else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "Unable to get CGImage from UIImage"
- ])
- }
- return
- }
-
- let detector = CIDetector(ofType: CIDetectorTypeQRCode,
- context: nil,
- options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])
-
- guard let qrDetector = detector else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "Unable to create QR code detector"
- ])
- }
- return
- }
-
- let ciImage = CIImage(cgImage: cgImage)
- let features = qrDetector.features(in: ciImage)
-
- if let qrFeature = features.first as? CIQRCodeFeature,
- let messageString = qrFeature.messageString {
- DispatchQueue.main.async {
- result([
- "success": true,
- "content": messageString
- ])
- }
- } else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "No QR code found in image"
- ])
- }
- }
- }
- }
-
- private func scanAllQrCodes(from imagePath: String, result: @escaping FlutterResult) {
- EnteQrPlugin.detectionQueue.async {
- guard let image = UIImage(contentsOfFile: imagePath) else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "Unable to load image from path: \(imagePath)"
- ])
- }
- return
- }
-
- guard let cgImage = image.cgImage else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "Unable to get CGImage from UIImage"
- ])
- }
- return
- }
-
- let detector = CIDetector(ofType: CIDetectorTypeQRCode,
- context: nil,
- options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])
-
- guard let qrDetector = detector else {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "Unable to create QR code detector"
- ])
- }
- return
- }
-
- let ciImage = CIImage(cgImage: cgImage)
- let features = qrDetector.features(in: ciImage)
-
- let imageWidth = CGFloat(cgImage.width)
- let imageHeight = CGFloat(cgImage.height)
-
- var detections: [[String: Any]] = []
-
- for feature in features {
- guard let qrFeature = feature as? CIQRCodeFeature,
- let messageString = qrFeature.messageString else {
- continue
- }
-
- // Core Image has origin at bottom-left with y-up.
- // Convert to normalized [0,1] coords with origin top-left, y-down.
- let minX = min(qrFeature.topLeft.x, qrFeature.bottomLeft.x)
- let maxX = max(qrFeature.topRight.x, qrFeature.bottomRight.x)
- // In CI coords, topLeft.y > bottomLeft.y (y goes up)
- let minYci = min(qrFeature.bottomLeft.y, qrFeature.bottomRight.y)
- let maxYci = max(qrFeature.topLeft.y, qrFeature.topRight.y)
-
- // Add padding around finder patterns (matching Android's 15%)
- let padX = (maxX - minX) * 0.15
- let padY = (maxYci - minYci) * 0.15
- let paddedMinX = max(minX - padX, 0)
- let paddedMaxX = min(maxX + padX, imageWidth)
- let paddedMinYci = max(minYci - padY, 0)
- let paddedMaxYci = min(maxYci + padY, imageHeight)
-
- // Flip y: top-left origin
- let normX = paddedMinX / imageWidth
- let normY = 1.0 - (paddedMaxYci / imageHeight)
- let normW = (paddedMaxX - paddedMinX) / imageWidth
- let normH = (paddedMaxYci - paddedMinYci) / imageHeight
-
- detections.append([
- "content": messageString,
- "x": Double(normX),
- "y": Double(normY),
- "width": Double(normW),
- "height": Double(normH),
- ])
- }
-
- if detections.isEmpty {
- DispatchQueue.main.async {
- result([
- "success": false,
- "error": "No QR code found in image"
- ])
- }
- } else {
- DispatchQueue.main.async {
- result([
- "success": true,
- "detections": detections
- ])
- }
- }
- }
- }
-}
diff --git a/mobile/apps/auth/plugins/qr/lib/ente_qr.dart b/mobile/apps/auth/plugins/qr/lib/ente_qr.dart
deleted file mode 100644
index 4dd2f22ce5..0000000000
--- a/mobile/apps/auth/plugins/qr/lib/ente_qr.dart
+++ /dev/null
@@ -1,28 +0,0 @@
-import 'package:ente_auth_qr/ente_qr_platform_interface.dart';
-
-export 'ente_qr_platform_interface.dart'
- show QrDetection, QrScanResult, QrScanResults;
-
-class EnteQr {
- Future<String?> getPlatformVersion() {
- return EnteQrPlatform.instance.getPlatformVersion();
- }
-
- /// Scans a QR code from an image file at the given path.
- ///
- /// [imagePath] - The file path to the image containing the QR code
- ///
- /// Returns a [QrScanResult] containing either the QR code content on success
- /// or an error message on failure.
- Future<QrScanResult> scanQrFromImage(String imagePath) {
- return EnteQrPlatform.instance.scanQrFromImage(imagePath);
- }
-
- /// Scans all QR codes from an image file at the given path.
- ///
- /// Returns a [QrScanResults] containing a list of [QrDetection] with
- /// content and normalized bounding boxes for each detected QR code.
- Future<QrScanResults> scanAllQrFromImage(String imagePath) {
- return EnteQrPlatform.instance.scanAllQrFromImage(imagePath);
- }
-}
diff --git a/mobile/apps/auth/plugins/qr/lib/ente_qr_method_channel.dart b/mobile/apps/auth/plugins/qr/lib/ente_qr_method_channel.dart
deleted file mode 100644
index 937a16ff7e..0000000000
--- a/mobile/apps/auth/plugins/qr/lib/ente_qr_method_channel.dart
+++ /dev/null
@@ -1,93 +0,0 @@
-import 'package:ente_auth_qr/ente_qr_platform_interface.dart';
-import 'package:flutter/foundation.dart';
-import 'package:flutter/services.dart';
-
-/// An implementation of [EnteQrPlatform] that uses method channels.
-class MethodChannelEnteQr extends EnteQrPlatform {
- /// The method channel used to interact with the native platform.
- @visibleForTesting
- final methodChannel = const MethodChannel('ente_qr');
-
- @override
- Future<String?> getPlatformVersion() async {
- final version = await methodChannel.invokeMethod<String>(
- 'getPlatformVersion',
- );
- return version;
- }
-
- @override
- Future<QrScanResult> scanQrFromImage(String imagePath) async {
- try {
- final dynamic result = await methodChannel.invokeMethod(
- 'scanQrFromImage',
- {'imagePath': imagePath},
- );
-
- if (result == null) {
- return QrScanResult.error('Failed to scan QR code');
- }
-
- // Convert to Map<String, dynamic> safely
- final Map<String, dynamic> resultMap = Map<String, dynamic>.from(
- result as Map,
- );
-
- final bool success = resultMap['success'] as bool? ?? false;
- if (success) {
- final String? content = resultMap['content'] as String?;
- if (content != null && content.isNotEmpty) {
- return QrScanResult.success(content);
- } else {
- return QrScanResult.error('No QR code found in image');
- }
- } else {
- final String? error = resultMap['error'] as String?;
- return QrScanResult.error(error ?? 'Unknown error occurred');
- }
- } on PlatformException catch (e) {
- return QrScanResult.error('Platform error: ${e.message}');
- } catch (e) {
- return QrScanResult.error('Unexpected error: $e');
- }
- }
-
- @override
- Future<QrScanResults> scanAllQrFromImage(String imagePath) async {
- try {
- final dynamic result = await methodChannel.invokeMethod(
- 'scanAllQrFromImage',
- {'imagePath': imagePath},
- );
-
- if (result == null) {
- return QrScanResults.error('Failed to scan QR codes');
- }
-
- final Map<String, dynamic> resultMap = Map<String, dynamic>.from(
- result as Map,
- );
-
- final bool success = resultMap['success'] as bool? ?? false;
- if (success) {
- final List<dynamic>? rawDetections =
- resultMap['detections'] as List<dynamic>?;
- if (rawDetections != null && rawDetections.isNotEmpty) {
- final detections = rawDetections.map((d) {
- return QrDetection.fromMap(Map<String, dynamic>.from(d as Map));
- }).toList();
- return QrScanResults.fromDetections(detections);
- } else {
- return QrScanResults.error('No QR codes found in image');
- }
- } else {
- final String? error = resultMap['error'] as String?;
- return QrScanResults.error(error ?? 'Unknown error occurred');
- }
- } on PlatformException catch (e) {
- return QrScanResults.error('Platform error: ${e.message}');
- } catch (e) {
- return QrScanResults.error('Unexpected error: $e');
- }
- }
-}
diff --git a/mobile/apps/auth/plugins/qr/lib/ente_qr_platform_interface.dart b/mobile/apps/auth/plugins/qr/lib/ente_qr_platform_interface.dart
deleted file mode 100644
index 0dee60ae08..0000000000
--- a/mobile/apps/auth/plugins/qr/lib/ente_qr_platform_interface.dart
+++ /dev/null
@@ -1,114 +0,0 @@
-import 'package:ente_auth_qr/ente_qr_method_channel.dart';
-import 'package:plugin_platform_interface/plugin_platform_interface.dart';
-
-/// The result of QR code scanning
-class QrScanResult {
- final String? content;
- final String? error;
- final bool success;
-
- const QrScanResult({this.content, this.error, required this.success});
-
- factory QrScanResult.success(String content) {
- return QrScanResult(content: content, success: true);
- }
-
- factory QrScanResult.error(String error) {
- return QrScanResult(error: error, success: false);
- }
-}
-
-/// A single detected QR code with its content and normalized bounding box.
-class QrDetection {
- /// The decoded QR code content.
- final String content;
-
- /// Normalized x coordinate of the bounding box (0.0 to 1.0).
- final double x;
-
- /// Normalized y coordinate of the bounding box (0.0 to 1.0).
- final double y;
-
- /// Normalized width of the bounding box (0.0 to 1.0).
- final double width;
-
- /// Normalized height of the bounding box (0.0 to 1.0).
- final double height;
-
- const QrDetection({
- required this.content,
- required this.x,
- required this.y,
- required this.width,
- required this.height,
- });
-
- factory QrDetection.fromMap(Map<String, dynamic> map) {
- return QrDetection(
- content: map['content'] as String,
- x: (map['x'] as num).toDouble(),
- y: (map['y'] as num).toDouble(),
- width: (map['width'] as num).toDouble(),
- height: (map['height'] as num).toDouble(),
- );
- }
-}
-
-/// The result of scanning for multiple QR codes.
-class QrScanResults {
- final List<QrDetection> detections;
- final String? error;
- final bool success;
-
- const QrScanResults({
- required this.detections,
- this.error,
- required this.success,
- });
-
- factory QrScanResults.fromDetections(List<QrDetection> detections) {
- return QrScanResults(detections: detections, success: true);
- }
-
- factory QrScanResults.error(String error) {
- return QrScanResults(detections: const [], error: error, success: false);
- }
-}
-
-abstract class EnteQrPlatform extends PlatformInterface {
- /// Constructs a EnteQrPlatform.
- EnteQrPlatform() : super(token: _token);
-
- static final Object _token = Object();
-
- static EnteQrPlatform _instance = MethodChannelEnteQr();
-
- /// The default instance of [EnteQrPlatform] to use.
- ///
- /// Defaults to [MethodChannelEnteQr].
- static EnteQrPlatform get instance => _instance;
-
- /// Platform-specific implementations should set this with their own
- /// platform-specific class that extends [EnteQrPlatform] when
- /// they register themselves.
- static set instance(EnteQrPlatform instance) {
- PlatformInterface.verifyToken(instance, _token);
- _instance = instance;
- }
-
- Future<String?> getPlatformVersion() {
- throw UnimplementedError('platformVersion() has not been implemented.');
- }
-
- /// Scans a QR code from an image file at the given path.
- /// Returns the QR code content as a string if successful, null otherwise.
- Future<QrScanResult> scanQrFromImage(String imagePath) {
- throw UnimplementedError('scanQrFromImage() has not been implemented.');
- }
-
- /// Scans all QR codes from an image file at the given path.
- /// Returns a list of detections with content and bounding boxes.
- Future<QrScanResults> scanAllQrFromImage(String imagePath) {
- throw UnimplementedError('scanAllQrFromImage() has not been implemented.');
- }
-}
diff --git a/mobile/apps/auth/plugins/qr/pubspec.lock b/mobile/apps/auth/plugins/qr/pubspec.lock
deleted file mode 100644
index f84604d3ee..0000000000
--- a/mobile/apps/auth/plugins/qr/pubspec.lock
+++ /dev/null
@@ -1,213 +0,0 @@
-# Generated by pub
-# See https://dart.dev/tools/pub/glossary#lockfile
-packages:
- async:
- dependency: transitive
- description:
- name: async
- sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37
- url: "https://pub.dev"
- source: hosted
- version: "2.13.1"
- boolean_selector:
- dependency: transitive
- description:
- name: boolean_selector
- sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
- url: "https://pub.dev"
- source: hosted
- version: "2.1.2"
- characters:
- dependency: transitive
- description:
- name: characters
- sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
- url: "https://pub.dev"
- source: hosted
- version: "1.4.0"
- clock:
- dependency: transitive
- description:
- name: clock
- sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
- url: "https://pub.dev"
- source: hosted
- version: "1.1.2"
- collection:
- dependency: transitive
- description:
- name: collection
- sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
- url: "https://pub.dev"
- source: hosted
- version: "1.19.1"
- fake_async:
- dependency: transitive
- description:
- name: fake_async
- sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
- url: "https://pub.dev"
- source: hosted
- version: "1.3.3"
- flutter:
- dependency: "direct main"
- description: flutter
- source: sdk
- version: "0.0.0"
- flutter_lints:
- dependency: "direct dev"
- description:
- name: flutter_lints
- sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1"
- url: "https://pub.dev"
- source: hosted
- version: "6.0.0"
- flutter_test:
- dependency: "direct dev"
- description: flutter
- source: sdk
- version: "0.0.0"
- leak_tracker:
- dependency: transitive
- description:
- name: leak_tracker
- sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
- url: "https://pub.dev"
- source: hosted
- version: "11.0.2"
- leak_tracker_flutter_testing:
- dependency: transitive
- description:
- name: leak_tracker_flutter_testing
- sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
- url: "https://pub.dev"
- source: hosted
- version: "3.0.10"
- leak_tracker_testing:
- dependency: transitive
- description:
- name: leak_tracker_testing
- sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
- url: "https://pub.dev"
- source: hosted
- version: "3.0.2"
- lints:
- dependency: transitive
- description:
- name: lints
- sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df"
- url: "https://pub.dev"
- source: hosted
- version: "6.1.0"
- matcher:
- dependency: transitive
- description:
- name: matcher
- sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
- url: "https://pub.dev"
- source: hosted
- version: "0.12.17"
- material_color_utilities:
- dependency: transitive
- description:
- name: material_color_utilities
- sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
- url: "https://pub.dev"
- source: hosted
- version: "0.11.1"
- meta:
- dependency: transitive
- description:
- name: meta
- sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
- url: "https://pub.dev"
- source: hosted
- version: "1.17.0"
- path:
- dependency: transitive
- description:
- name: path
- sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
- url: "https://pub.dev"
- source: hosted
- version: "1.9.1"
- plugin_platform_interface:
- dependency: "direct main"
- description:
- name: plugin_platform_interface
- sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
- url: "https://pub.dev"
- source: hosted
- version: "2.1.8"
- sky_engine:
- dependency: transitive
- description: flutter
- source: sdk
- version: "0.0.0"
- source_span:
- dependency: transitive
- description:
- name: source_span
- sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab"
- url: "https://pub.dev"
- source: hosted
- version: "1.10.2"
- stack_trace:
- dependency: transitive
- description:
- name: stack_trace
- sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
- url: "https://pub.dev"
- source: hosted
- version: "1.12.1"
- stream_channel:
- dependency: transitive
- description:
- name: stream_channel
- sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
- url: "https://pub.dev"
- source: hosted
- version: "2.1.4"
- string_scanner:
- dependency: transitive
- description:
- name: string_scanner
- sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
- url: "https://pub.dev"
- source: hosted
- version: "1.4.1"
- term_glyph:
- dependency: transitive
- description:
- name: term_glyph
- sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
- url: "https://pub.dev"
- source: hosted
- version: "1.2.2"
- test_api:
- dependency: transitive
- description:
- name: test_api
- sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
- url: "https://pub.dev"
- source: hosted
- version: "0.7.7"
- vector_math:
- dependency: transitive
- description:
- name: vector_math
- sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
- url: "https://pub.dev"
- source: hosted
- version: "2.2.0"
- vm_service:
- dependency: transitive
- description:
- name: vm_service
- sha256: "0016aef94fc66495ac78af5859181e3f3bf2026bd8eecc72b9565601e19ab360"
- url: "https://pub.dev"
- source: hosted
- version: "15.2.0"
-sdks:
- dart: ">=3.10.0 <4.0.0"
- flutter: ">=3.18.0-18.0.pre.54"
diff --git a/mobile/apps/auth/plugins/qr/pubspec.yaml b/mobile/apps/auth/plugins/qr/pubspec.yaml
deleted file mode 100644
index fbf69ce87e..0000000000
--- a/mobile/apps/auth/plugins/qr/pubspec.yaml
+++ /dev/null
@@ -1,29 +0,0 @@
-name: ente_auth_qr
-description: "A QR code reader plugin for Ente."
-version: 0.0.1
-homepage: https://ente.com
-
-environment:
- sdk: ">=3.10.0 <4.0.0"
- flutter: '>=3.3.0'
-
-dependencies:
- flutter:
- sdk: flutter
- plugin_platform_interface: 2.1.8
-
-dev_dependencies:
- flutter_lints: 6.0.0
- flutter_test:
- sdk: flutter
-
-# The following section is specific to Flutter packages.
-flutter:
- # This section identifies this Flutter project as a plugin project.
- plugin:
- platforms:
- android:
- package: io.ente.auth.ente_auth_qr
- pluginClass: EnteQrPlugin
- ios:
- pluginClass: EnteQrPlugin
diff --git a/mobile/apps/auth/plugins/qr/test/ente_qr_test.dart b/mobile/apps/auth/plugins/qr/test/ente_qr_test.dart
deleted file mode 100644
index 88f43d1c46..0000000000
--- a/mobile/apps/auth/plugins/qr/test/ente_qr_test.dart
+++ /dev/null
@@ -1,36 +0,0 @@
-import 'package:ente_auth_qr/ente_qr.dart';
-import 'package:ente_auth_qr/ente_qr_method_channel.dart';
-import 'package:ente_auth_qr/ente_qr_platform_interface.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:plugin_platform_interface/plugin_platform_interface.dart';
-
-class MockEnteQrPlatform
- with MockPlatformInterfaceMixin
- implements EnteQrPlatform {
- @override
- Future<String?> getPlatformVersion() => Future.value('42');
-
- @override
- Future<QrScanResult> scanQrFromImage(String imagePath) =>
- Future.value(QrScanResult.error('Mock implementation'));
-
- @override
- Future<QrScanResults> scanAllQrFromImage(String imagePath) =>
- Future.value(QrScanResults.error('Mock implementation'));
-}
-
-void main() {
- final EnteQrPlatform initialPlatform = EnteQrPlatform.instance;
-
- test('$MethodChannelEnteQr is the default instance', () {
- expect(initialPlatform, isInstanceOf<MethodChannelEnteQr>());
- });
-
- test('getPlatformVersion', () async {
- final EnteQr enteQrPlugin = EnteQr();
- final MockEnteQrPlatform fakePlatform = MockEnteQrPlatform();
- EnteQrPlatform.instance = fakePlatform;
-
- expect(await enteQrPlugin.getPlatformVersion(), '42');
- });
-}
diff --git a/mobile/apps/auth/pubspec.lock b/mobile/apps/auth/pubspec.lock
index 0b4df97d34..830ac3a486 100644
--- a/mobile/apps/auth/pubspec.lock
+++ b/mobile/apps/auth/pubspec.lock
@@ -112,6 +112,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
+ charcode:
+ dependency: transitive
+ description:
+ name: charcode
+ sha256: fb0f1107cac15a5ea6ef0a6ef71a807b9e4267c713bb93e00e92d737cc8dbd8a
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.4.0"
checked_yaml:
dependency: transitive
description:
@@ -311,13 +319,6 @@ packages:
relative: true
source: path
version: "1.0.0"
- ente_auth_qr:
- dependency: "direct main"
- description:
- path: "plugins/qr"
- relative: true
- source: path
- version: "0.0.1"
ente_base:
dependency: "direct main"
description:
@@ -390,6 +391,13 @@ packages:
relative: true
source: path
version: "1.0.0"
+ ente_qr:
+ dependency: "direct main"
+ description:
+ path: "../../packages/ente_qr"
+ relative: true
+ source: path
+ version: "0.0.1"
ente_strings:
dependency: "direct main"
description:
@@ -1787,6 +1795,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.3"
+ zxing2:
+ dependency: transitive
+ description:
+ name: zxing2
+ sha256: "2677c49a3b9ca9457cb1d294fd4bd5041cac6aab8cdb07b216ba4e98945c684f"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.2.4"
sdks:
dart: ">=3.10.3 <4.0.0"
flutter: ">=3.38.4"
diff --git a/mobile/apps/auth/pubspec.yaml b/mobile/apps/auth/pubspec.yaml
index 59f7240200..ac299e4f09 100644
--- a/mobile/apps/auth/pubspec.yaml
+++ b/mobile/apps/auth/pubspec.yaml
@@ -27,8 +27,6 @@ dependencies:
email_validator: 3.0.0
ente_accounts:
path: ../../packages/accounts
- ente_auth_qr:
- path: plugins/qr
ente_base:
path: ../../packages/base
ente_configuration:
@@ -47,6 +45,8 @@ dependencies:
path: ../../packages/network
ente_pure_utils:
path: ../../packages/ente_pure_utils
+ ente_qr:
+ path: ../../packages/ente_qr
ente_strings:
path: ../../packages/strings
ente_ui:
diff --git a/mobile/apps/photos/android/build.gradle b/mobile/apps/photos/android/build.gradle
index 2bcf235131..6386cd055f 100644
--- a/mobile/apps/photos/android/build.gradle
+++ b/mobile/apps/photos/android/build.gradle
@@ -8,6 +8,7 @@ allprojects {
google()
jcenter()
mavenCentral()
+ maven { url 'https://jitpack.io' }
// mavenLocal() // for FDroid
maven {
url "${project(':ffmpeg_kit_flutter').projectDir}/libs"
diff --git a/mobile/apps/photos/ios/Podfile.lock b/mobile/apps/photos/ios/Podfile.lock
index a2e0c8075d..f665d0bf01 100644
--- a/mobile/apps/photos/ios/Podfile.lock
+++ b/mobile/apps/photos/ios/Podfile.lock
@@ -491,7 +491,7 @@ SPEC CHECKSUMS:
dart_ui_isolate: 46f6714abe6891313267153ef6f9748d8ecfcab1
device_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbe
ente_photos_rust: a9e1166cc460dda69acd56fbed21afe87dfef562
- ente_qr: d1a6c708e9b2f8166fd20963562a89b122110d25
+ ente_qr: 86beaf5d2644705db9b565b32dd8b82c05fb36af
ente_rust: d0197ebd5460e8f67576579452b073d698404abe
ffmpeg_kit_custom: 682b4f2f1ff1f8abae5a92f6c3540f2441d5be99
ffmpeg_kit_flutter: 915b345acc97d4142e8a9a8549d177ff10f043f5
diff --git a/mobile/apps/photos/plugins/ente_qr/analysis_options.yaml b/mobile/apps/photos/plugins/ente_qr/analysis_options.yaml
deleted file mode 100644
index f04c6cf0f3..0000000000
--- a/mobile/apps/photos/plugins/ente_qr/analysis_options.yaml
+++ /dev/null
@@ -1 +0,0 @@
-include: ../../analysis_options.yaml
diff --git a/mobile/apps/photos/plugins/ente_qr/android/src/main/AndroidManifest.xml b/mobile/apps/photos/plugins/ente_qr/android/src/main/AndroidManifest.xml
deleted file mode 100644
index a2f47b6057..0000000000
--- a/mobile/apps/photos/plugins/ente_qr/android/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-<manifest xmlns:android="http://schemas.android.com/apk/res/android">
-</manifest>
diff --git a/mobile/apps/photos/pubspec.lock b/mobile/apps/photos/pubspec.lock
index b32d56735f..c9aecb45c2 100644
--- a/mobile/apps/photos/pubspec.lock
+++ b/mobile/apps/photos/pubspec.lock
@@ -306,6 +306,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
+ charcode:
+ dependency: transitive
+ description:
+ name: charcode
+ sha256: fb0f1107cac15a5ea6ef0a6ef71a807b9e4267c713bb93e00e92d737cc8dbd8a
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.4.0"
checked_yaml:
dependency: transitive
description:
@@ -638,7 +646,7 @@ packages:
ente_qr:
dependency: "direct main"
description:
- path: "plugins/ente_qr"
+ path: "../../packages/ente_qr"
relative: true
source: path
version: "0.0.1"
@@ -3149,6 +3157,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.3"
+ zxing2:
+ dependency: transitive
+ description:
+ name: zxing2
+ sha256: "2677c49a3b9ca9457cb1d294fd4bd5041cac6aab8cdb07b216ba4e98945c684f"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.2.4"
sdks:
dart: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index c05ba40e7b..8240581912 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -71,7 +71,7 @@ dependencies:
ente_pure_utils:
path: ../../packages/ente_pure_utils
ente_qr:
- path: plugins/ente_qr
+ path: ../../packages/ente_qr
ente_qr_ui:
path: ../../packages/qr
ente_rust:
diff --git a/mobile/apps/photos/pubspec_overrides.yaml b/mobile/apps/photos/pubspec_overrides.yaml
index 412735f532..fbbe468a57 100644
--- a/mobile/apps/photos/pubspec_overrides.yaml
+++ b/mobile/apps/photos/pubspec_overrides.yaml
@@ -44,6 +44,6 @@ dependency_overrides:
ente_contacts:
path: ../../packages/contacts
ente_qr:
- path: plugins/ente_qr
+ path: ../../packages/ente_qr
ente_components:
path: ../../packages/ente_components
diff --git a/mobile/apps/auth/plugins/qr/.metadata b/mobile/packages/ente_qr/.metadata
similarity index 100%
rename from mobile/apps/auth/plugins/qr/.metadata
rename to mobile/packages/ente_qr/.metadata
diff --git a/mobile/apps/photos/plugins/ente_qr/CHANGELOG.md b/mobile/packages/ente_qr/CHANGELOG.md
similarity index 65%
rename from mobile/apps/photos/plugins/ente_qr/CHANGELOG.md
rename to mobile/packages/ente_qr/CHANGELOG.md
index 2677363d9e..029120171b 100644
--- a/mobile/apps/photos/plugins/ente_qr/CHANGELOG.md
+++ b/mobile/packages/ente_qr/CHANGELOG.md
@@ -2,7 +2,7 @@
- Initial release of ente_qr plugin
- Support for scanning QR codes from image files
-- Android implementation using ZXing library
-- iOS implementation using Core Image framework
+- Android implementation using zxing-cpp
+- iOS implementation using Vision
- Comprehensive error handling
- Example app demonstrating usage with file picker
diff --git a/mobile/apps/photos/plugins/ente_qr/README.md b/mobile/packages/ente_qr/README.md
similarity index 92%
rename from mobile/apps/photos/plugins/ente_qr/README.md
rename to mobile/packages/ente_qr/README.md
index e52899ccb2..49209809e4 100644
--- a/mobile/apps/photos/plugins/ente_qr/README.md
+++ b/mobile/packages/ente_qr/README.md
@@ -1,12 +1,13 @@
# ente_qr
-A Flutter plugin for scanning QR codes from image files. This plugin provides a simple interface to scan QR codes from images on both Android and iOS platforms.
+A Flutter plugin for scanning QR codes from image files. This plugin provides a simple interface to scan QR codes from images across Ente mobile and desktop apps.
## Features
- Scan QR codes from image files
-- Support for Android (using ZXing library)
-- Support for iOS (using AVFoundation/Core Image)
+- Support for Android using zxing-cpp
+- Support for iOS and macOS using Vision
+- Dart fallback for desktop platforms without native plugin support
- Returns structured results with error handling
- Works with images from file picker or camera
@@ -17,9 +18,9 @@ A Flutter plugin for scanning QR codes from image files. This plugin provides a
| Android | βœ… |
| iOS | βœ… |
| Web | ❌ |
-| macOS | ❌ |
-| Windows | ❌ |
-| Linux | ❌ |
+| macOS | βœ… |
+| Windows | βœ… |
+| Linux | βœ… |
## Installation
diff --git a/mobile/apps/auth/plugins/qr/analysis_options.yaml b/mobile/packages/ente_qr/analysis_options.yaml
similarity index 100%
rename from mobile/apps/auth/plugins/qr/analysis_options.yaml
rename to mobile/packages/ente_qr/analysis_options.yaml
diff --git a/mobile/apps/photos/plugins/ente_qr/android/build.gradle b/mobile/packages/ente_qr/android/build.gradle
similarity index 95%
rename from mobile/apps/photos/plugins/ente_qr/android/build.gradle
rename to mobile/packages/ente_qr/android/build.gradle
index 4ee0a77c87..ed9c6051cf 100644
--- a/mobile/apps/photos/plugins/ente_qr/android/build.gradle
+++ b/mobile/packages/ente_qr/android/build.gradle
@@ -1,4 +1,4 @@
-group 'io.ente.photos.ente_qr'
+group 'io.ente.ente_qr'
version '1.0-SNAPSHOT'
buildscript {
@@ -6,6 +6,7 @@ buildscript {
repositories {
google()
mavenCentral()
+ maven { url 'https://jitpack.io' }
}
dependencies {
@@ -18,7 +19,6 @@ rootProject.allprojects {
repositories {
google()
mavenCentral()
- maven { url 'https://jitpack.io' }
}
}
@@ -26,7 +26,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
- namespace 'io.ente.photos.ente_qr'
+ namespace 'io.ente.ente_qr'
compileSdk 36
compileOptions {
diff --git a/mobile/apps/photos/plugins/ente_qr/android/settings.gradle b/mobile/packages/ente_qr/android/settings.gradle
similarity index 100%
rename from mobile/apps/photos/plugins/ente_qr/android/settings.gradle
rename to mobile/packages/ente_qr/android/settings.gradle
diff --git a/mobile/apps/auth/plugins/qr/android/src/main/AndroidManifest.xml b/mobile/packages/ente_qr/android/src/main/AndroidManifest.xml
similarity index 100%
rename from mobile/apps/auth/plugins/qr/android/src/main/AndroidManifest.xml
rename to mobile/packages/ente_qr/android/src/main/AndroidManifest.xml
diff --git a/mobile/apps/photos/plugins/ente_qr/android/src/main/kotlin/io/ente/photos/ente_qr/EnteQrPlugin.kt b/mobile/packages/ente_qr/android/src/main/kotlin/io/ente/ente_qr/EnteQrPlugin.kt
similarity index 98%
rename from mobile/apps/photos/plugins/ente_qr/android/src/main/kotlin/io/ente/photos/ente_qr/EnteQrPlugin.kt
rename to mobile/packages/ente_qr/android/src/main/kotlin/io/ente/ente_qr/EnteQrPlugin.kt
index e6a50dd723..2b9ff5fd7e 100644
--- a/mobile/apps/photos/plugins/ente_qr/android/src/main/kotlin/io/ente/photos/ente_qr/EnteQrPlugin.kt
+++ b/mobile/packages/ente_qr/android/src/main/kotlin/io/ente/ente_qr/EnteQrPlugin.kt
@@ -1,4 +1,4 @@
-package io.ente.photos.ente_qr
+package io.ente.ente_qr
import android.graphics.Bitmap
import android.graphics.BitmapFactory
@@ -153,7 +153,7 @@ class EnteQrPlugin: FlutterPlugin, MethodCallHandler {
if (results != null && results.isNotEmpty()) {
val text = results[0].text
- if (text != null && text.isNotEmpty()) {
+ if (text.isNotEmpty()) {
return mapOf("success" to true, "content" to text)
}
}
@@ -165,7 +165,7 @@ class EnteQrPlugin: FlutterPlugin, MethodCallHandler {
)
if (fallbackResults != null && fallbackResults.isNotEmpty()) {
val text = fallbackResults[0].text
- if (text != null && text.isNotEmpty()) {
+ if (text.isNotEmpty()) {
return mapOf("success" to true, "content" to text)
}
}
diff --git a/mobile/apps/photos/plugins/ente_qr/ios/Classes/EnteQrPlugin.swift b/mobile/packages/ente_qr/ios/Classes/EnteQrPlugin.swift
similarity index 100%
rename from mobile/apps/photos/plugins/ente_qr/ios/Classes/EnteQrPlugin.swift
rename to mobile/packages/ente_qr/ios/Classes/EnteQrPlugin.swift
diff --git a/mobile/apps/photos/plugins/ente_qr/ios/ente_qr.podspec b/mobile/packages/ente_qr/ios/ente_qr.podspec
similarity index 96%
rename from mobile/apps/photos/plugins/ente_qr/ios/ente_qr.podspec
rename to mobile/packages/ente_qr/ios/ente_qr.podspec
index 11df118b30..f52d6d032b 100644
--- a/mobile/apps/photos/plugins/ente_qr/ios/ente_qr.podspec
+++ b/mobile/packages/ente_qr/ios/ente_qr.podspec
@@ -15,7 +15,7 @@ A QR code reader plugin for Ente.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
- s.platform = :ios, '12.0'
+ s.platform = :ios, '9.0'
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
diff --git a/mobile/apps/photos/plugins/ente_qr/lib/ente_qr.dart b/mobile/packages/ente_qr/lib/ente_qr.dart
similarity index 65%
rename from mobile/apps/photos/plugins/ente_qr/lib/ente_qr.dart
rename to mobile/packages/ente_qr/lib/ente_qr.dart
index ee7f3f2e10..fd0e56d63d 100644
--- a/mobile/apps/photos/plugins/ente_qr/lib/ente_qr.dart
+++ b/mobile/packages/ente_qr/lib/ente_qr.dart
@@ -1,9 +1,19 @@
+import 'package:ente_qr/ente_qr_method_channel.dart';
import 'package:ente_qr/ente_qr_platform_interface.dart';
+import 'package:ente_qr/src/desktop_qr_platform.dart';
export 'ente_qr_platform_interface.dart'
show QrDetection, QrScanResult, QrScanResults;
class EnteQr {
+ EnteQrPlatform get _scanPlatform {
+ final currentPlatform = EnteQrPlatform.instance;
+ if (currentPlatform is! MethodChannelEnteQr) {
+ return currentPlatform;
+ }
+ return desktopQrPlatform() ?? currentPlatform;
+ }
+
Future<String?> getPlatformVersion() {
return EnteQrPlatform.instance.getPlatformVersion();
}
@@ -15,7 +25,7 @@ class EnteQr {
/// Returns a [QrScanResult] containing either the QR code content on success
/// or an error message on failure.
Future<QrScanResult> scanQrFromImage(String imagePath) {
- return EnteQrPlatform.instance.scanQrFromImage(imagePath);
+ return _scanPlatform.scanQrFromImage(imagePath);
}
/// Scans all QR codes from an image file at the given path.
@@ -23,6 +33,6 @@ class EnteQr {
/// Returns a [QrScanResults] containing a list of [QrDetection] with
/// content and normalized bounding boxes for each detected QR code.
Future<QrScanResults> scanAllQrFromImage(String imagePath) {
- return EnteQrPlatform.instance.scanAllQrFromImage(imagePath);
+ return _scanPlatform.scanAllQrFromImage(imagePath);
}
}
diff --git a/mobile/apps/photos/plugins/ente_qr/lib/ente_qr_method_channel.dart b/mobile/packages/ente_qr/lib/ente_qr_method_channel.dart
similarity index 100%
rename from mobile/apps/photos/plugins/ente_qr/lib/ente_qr_method_channel.dart
rename to mobile/packages/ente_qr/lib/ente_qr_method_channel.dart
diff --git a/mobile/apps/photos/plugins/ente_qr/lib/ente_qr_platform_interface.dart b/mobile/packages/ente_qr/lib/ente_qr_platform_interface.dart
similarity index 100%
rename from mobile/apps/photos/plugins/ente_qr/lib/ente_qr_platform_interface.dart
rename to mobile/packages/ente_qr/lib/ente_qr_platform_interface.dart
diff --git a/mobile/packages/ente_qr/lib/src/dart_zxing_qr_platform.dart b/mobile/packages/ente_qr/lib/src/dart_zxing_qr_platform.dart
new file mode 100644
index 0000000000..4125f999b6
--- /dev/null
+++ b/mobile/packages/ente_qr/lib/src/dart_zxing_qr_platform.dart
@@ -0,0 +1,89 @@
+import 'dart:io';
+
+import 'package:ente_qr/ente_qr_platform_interface.dart';
+import 'package:image/image.dart' as img;
+import 'package:zxing2/qrcode.dart';
+
+final class DartZxingQrPlatform extends EnteQrPlatform {
+ @override
+ Future<String?> getPlatformVersion() async {
+ return 'Dart zxing2';
+ }
+
+ @override
+ Future<QrScanResult> scanQrFromImage(String imagePath) async {
+ try {
+ final content = await _decodeQrFromImagePath(imagePath);
+ return QrScanResult.success(content);
+ } catch (e) {
+ return QrScanResult.error(e.toString());
+ }
+ }
+
+ @override
+ Future<QrScanResults> scanAllQrFromImage(String imagePath) async {
+ final result = await scanQrFromImage(imagePath);
+ final content = result.content;
+ if (!result.success || content == null) {
+ return QrScanResults.error(result.error ?? 'No QR code found in image');
+ }
+ return QrScanResults.fromDetections([
+ QrDetection(content: content, x: 0, y: 0, width: 1, height: 1),
+ ]);
+ }
+}
+
+Future<String> _decodeQrFromImagePath(String imagePath) async {
+ final file = File(imagePath);
+ if (!await file.exists()) {
+ throw StateError('Image file not found: $imagePath');
+ }
+
+ final bytes = await file.readAsBytes();
+ final image = img.decodeImage(bytes);
+ if (image == null) {
+ throw StateError('Unable to decode image file');
+ }
+
+ return _decodeImage(image).text;
+}
+
+Result _decodeImage(img.Image source) {
+ final attempts = <img.Image>[
+ source,
+ img.invert(img.Image.from(source)),
+ if (source.width > 1200 || source.height > 1200)
+ img.copyResize(
+ source,
+ width: source.width >= source.height ? 1200 : null,
+ height: source.height > source.width ? 1200 : null,
+ ),
+ ];
+
+ Object? lastError;
+ for (final attempt in attempts) {
+ final converted = attempt.convert(numChannels: 4);
+ final pixels = converted
+ .getBytes(order: img.ChannelOrder.abgr)
+ .buffer
+ .asInt32List();
+ final luminanceSource = RGBLuminanceSource(
+ converted.width,
+ converted.height,
+ pixels,
+ );
+
+ final hints = DecodeHints()..put(DecodeHintType.tryHarder);
+ for (final bitmap in [
+ BinaryBitmap(GlobalHistogramBinarizer(luminanceSource)),
+ BinaryBitmap(HybridBinarizer(luminanceSource)),
+ ]) {
+ try {
+ return QRCodeReader().decode(bitmap, hints: hints);
+ } catch (error) {
+ lastError = error;
+ }
+ }
+ }
+ throw StateError(lastError?.toString() ?? 'No QR code found in image');
+}
diff --git a/mobile/packages/ente_qr/lib/src/desktop_qr_platform.dart b/mobile/packages/ente_qr/lib/src/desktop_qr_platform.dart
new file mode 100644
index 0000000000..1e1d9443f1
--- /dev/null
+++ b/mobile/packages/ente_qr/lib/src/desktop_qr_platform.dart
@@ -0,0 +1,2 @@
+export 'desktop_qr_platform_stub.dart'
+ if (dart.library.io) 'desktop_qr_platform_io.dart';
diff --git a/mobile/packages/ente_qr/lib/src/desktop_qr_platform_io.dart b/mobile/packages/ente_qr/lib/src/desktop_qr_platform_io.dart
new file mode 100644
index 0000000000..8374d935e7
--- /dev/null
+++ b/mobile/packages/ente_qr/lib/src/desktop_qr_platform_io.dart
@@ -0,0 +1,11 @@
+import 'dart:io';
+
+import 'package:ente_qr/ente_qr_platform_interface.dart';
+import 'package:ente_qr/src/dart_zxing_qr_platform.dart';
+
+EnteQrPlatform? desktopQrPlatform() {
+ if (Platform.isWindows || Platform.isLinux) {
+ return DartZxingQrPlatform();
+ }
+ return null;
+}
diff --git a/mobile/packages/ente_qr/lib/src/desktop_qr_platform_stub.dart b/mobile/packages/ente_qr/lib/src/desktop_qr_platform_stub.dart
new file mode 100644
index 0000000000..6e9bff4baa
--- /dev/null
+++ b/mobile/packages/ente_qr/lib/src/desktop_qr_platform_stub.dart
@@ -0,0 +1,3 @@
+import 'package:ente_qr/ente_qr_platform_interface.dart';
+
+EnteQrPlatform? desktopQrPlatform() => null;
diff --git a/mobile/packages/ente_qr/macos/Classes/EnteQrPlugin.swift b/mobile/packages/ente_qr/macos/Classes/EnteQrPlugin.swift
new file mode 100644
index 0000000000..145ed93a32
--- /dev/null
+++ b/mobile/packages/ente_qr/macos/Classes/EnteQrPlugin.swift
@@ -0,0 +1,165 @@
+import Cocoa
+import FlutterMacOS
+import Vision
+
+public class EnteQrPlugin: NSObject, FlutterPlugin {
+ private static let detectionQueue = DispatchQueue(label: "io.ente.qr.detection", qos: .userInitiated)
+
+ public static func register(with registrar: FlutterPluginRegistrar) {
+ let channel = FlutterMethodChannel(name: "ente_qr", binaryMessenger: registrar.messenger)
+ let instance = EnteQrPlugin()
+ registrar.addMethodCallDelegate(instance, channel: channel)
+ }
+
+ public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
+ switch call.method {
+ case "getPlatformVersion":
+ result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString)
+ case "scanQrFromImage":
+ guard let imagePath = imagePath(from: call.arguments) else {
+ result([
+ "success": false,
+ "error": "Image path is required",
+ ])
+ return
+ }
+
+ scanQrCode(from: imagePath, result: result)
+ case "scanAllQrFromImage":
+ guard let imagePath = imagePath(from: call.arguments) else {
+ result([
+ "success": false,
+ "error": "Image path is required",
+ ])
+ return
+ }
+
+ scanAllQrCodes(from: imagePath, result: result)
+ default:
+ result(FlutterMethodNotImplemented)
+ }
+ }
+
+ private func imagePath(from arguments: Any?) -> String? {
+ guard let args = arguments as? [String: Any] else {
+ return nil
+ }
+ return args["imagePath"] as? String
+ }
+
+ private func scanQrCode(from imagePath: String, result: @escaping FlutterResult) {
+ detectQrCodes(from: imagePath) { detectionResult in
+ switch detectionResult {
+ case .success(let detections):
+ guard let content = detections.first?["content"] as? String else {
+ result([
+ "success": false,
+ "error": "No QR code found in image",
+ ])
+ return
+ }
+ result([
+ "success": true,
+ "content": content,
+ ])
+ case .failure(let error):
+ result([
+ "success": false,
+ "error": error.localizedDescription,
+ ])
+ }
+ }
+ }
+
+ private func scanAllQrCodes(from imagePath: String, result: @escaping FlutterResult) {
+ detectQrCodes(from: imagePath) { detectionResult in
+ switch detectionResult {
+ case .success(let detections):
+ result([
+ "success": true,
+ "detections": detections,
+ ])
+ case .failure(let error):
+ result([
+ "success": false,
+ "error": error.localizedDescription,
+ ])
+ }
+ }
+ }
+
+ private func detectQrCodes(
+ from imagePath: String,
+ completion: @escaping (Result<[[String: Any]], Error>) -> Void
+ ) {
+ EnteQrPlugin.detectionQueue.async {
+ do {
+ let cgImage = try self.loadCgImage(from: imagePath)
+ let request = VNDetectBarcodesRequest()
+ request.symbologies = [.qr]
+
+ let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])
+ try handler.perform([request])
+
+ let observations = request.results ?? []
+ let detections = observations.compactMap { observation -> [String: Any]? in
+ guard observation.symbology == .qr,
+ let payload = observation.payloadStringValue,
+ !payload.isEmpty else {
+ return nil
+ }
+
+ let box = observation.boundingBox
+ return [
+ "content": payload,
+ "x": Double(box.minX),
+ "y": Double(1.0 - box.maxY),
+ "width": Double(box.width),
+ "height": Double(box.height),
+ ]
+ }
+
+ DispatchQueue.main.async {
+ if detections.isEmpty {
+ completion(.failure(EnteQrError.noQrCodeFound))
+ } else {
+ completion(.success(detections))
+ }
+ }
+ } catch {
+ DispatchQueue.main.async {
+ completion(.failure(error))
+ }
+ }
+ }
+ }
+
+ private func loadCgImage(from imagePath: String) throws -> CGImage {
+ guard let image = NSImage(contentsOfFile: imagePath) else {
+ throw EnteQrError.unableToLoadImage
+ }
+
+ var proposedRect = NSRect(origin: .zero, size: image.size)
+ guard let cgImage = image.cgImage(forProposedRect: &proposedRect, context: nil, hints: nil) else {
+ throw EnteQrError.unableToCreateCgImage
+ }
+ return cgImage
+ }
+}
+
+private enum EnteQrError: LocalizedError {
+ case unableToLoadImage
+ case unableToCreateCgImage
+ case noQrCodeFound
+
+ var errorDescription: String? {
+ switch self {
+ case .unableToLoadImage:
+ return "Unable to load image from path"
+ case .unableToCreateCgImage:
+ return "Unable to create CGImage from image"
+ case .noQrCodeFound:
+ return "No QR code found in image"
+ }
+ }
+}
diff --git a/mobile/apps/auth/plugins/qr/ios/ente_auth_qr.podspec b/mobile/packages/ente_qr/macos/ente_qr.podspec
similarity index 62%
rename from mobile/apps/auth/plugins/qr/ios/ente_auth_qr.podspec
rename to mobile/packages/ente_qr/macos/ente_qr.podspec
index b4fb105854..813ef80b99 100644
--- a/mobile/apps/auth/plugins/qr/ios/ente_auth_qr.podspec
+++ b/mobile/packages/ente_qr/macos/ente_qr.podspec
@@ -1,9 +1,9 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
-# Run `pod lib lint ente_auth_qr.podspec` to validate before publishing.
+# Run `pod lib lint ente_qr.podspec` to validate before publishing.
#
Pod::Spec.new do |s|
- s.name = 'ente_auth_qr'
+ s.name = 'ente_qr'
s.version = '0.0.1'
s.summary = 'A QR code reader plugin for Ente.'
s.description = <<-DESC
@@ -14,10 +14,9 @@ A QR code reader plugin for Ente.
s.author = { 'Ente' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
- s.dependency 'Flutter'
- s.platform = :ios, '9.0'
+ s.dependency 'FlutterMacOS'
+ s.platform = :osx, '10.14'
- # Flutter.framework does not contain a i386 slice.
- s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
+ s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
end
diff --git a/mobile/apps/photos/plugins/ente_qr/pubspec.lock b/mobile/packages/ente_qr/pubspec.lock
similarity index 75%
rename from mobile/apps/photos/plugins/ente_qr/pubspec.lock
rename to mobile/packages/ente_qr/pubspec.lock
index f84604d3ee..824a846cc4 100644
--- a/mobile/apps/photos/plugins/ente_qr/pubspec.lock
+++ b/mobile/packages/ente_qr/pubspec.lock
@@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
+ archive:
+ dependency: transitive
+ description:
+ name: archive
+ sha256: a96e8b390886ee8abb49b7bd3ac8df6f451c621619f52a26e815fdcf568959ff
+ url: "https://pub.dev"
+ source: hosted
+ version: "4.0.9"
async:
dependency: transitive
description:
@@ -25,6 +33,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
+ charcode:
+ dependency: transitive
+ description:
+ name: charcode
+ sha256: fb0f1107cac15a5ea6ef0a6ef71a807b9e4267c713bb93e00e92d737cc8dbd8a
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.4.0"
clock:
dependency: transitive
description:
@@ -49,6 +65,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.3"
+ ffi:
+ dependency: transitive
+ description:
+ name: ffi
+ sha256: "6d7fd89431262d8f3125e81b50d3847a091d846eafcd4fdb88dd06f36d705a45"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.0"
+ fixnum:
+ dependency: transitive
+ description:
+ name: fixnum
+ sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.1.1"
flutter:
dependency: "direct main"
description: flutter
@@ -67,6 +99,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
+ image:
+ dependency: "direct main"
+ description:
+ name: image
+ sha256: "4e973fcf4caae1a4be2fa0a13157aa38a8f9cb049db6529aa00b4d71abc4d928"
+ url: "https://pub.dev"
+ source: hosted
+ version: "4.5.4"
leak_tracker:
dependency: transitive
description:
@@ -131,6 +171,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
+ petitparser:
+ dependency: transitive
+ description:
+ name: petitparser
+ sha256: "91bd59303e9f769f108f8df05e371341b15d59e995e6806aefab827b58336675"
+ url: "https://pub.dev"
+ source: hosted
+ version: "7.0.2"
plugin_platform_interface:
dependency: "direct main"
description:
@@ -139,6 +187,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
+ posix:
+ dependency: transitive
+ description:
+ name: posix
+ sha256: "185ef7606574f789b40f289c233efa52e96dead518aed988e040a10737febb07"
+ url: "https://pub.dev"
+ source: hosted
+ version: "6.5.0"
sky_engine:
dependency: transitive
description: flutter
@@ -208,6 +264,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "15.2.0"
+ xml:
+ dependency: transitive
+ description:
+ name: xml
+ sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025"
+ url: "https://pub.dev"
+ source: hosted
+ version: "6.6.1"
+ zxing2:
+ dependency: "direct main"
+ description:
+ name: zxing2
+ sha256: "2677c49a3b9ca9457cb1d294fd4bd5041cac6aab8cdb07b216ba4e98945c684f"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.2.4"
sdks:
dart: ">=3.10.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
diff --git a/mobile/apps/photos/plugins/ente_qr/pubspec.yaml b/mobile/packages/ente_qr/pubspec.yaml
similarity index 83%
rename from mobile/apps/photos/plugins/ente_qr/pubspec.yaml
rename to mobile/packages/ente_qr/pubspec.yaml
index 5fd373c61d..de23ce91c1 100644
--- a/mobile/apps/photos/plugins/ente_qr/pubspec.yaml
+++ b/mobile/packages/ente_qr/pubspec.yaml
@@ -10,7 +10,9 @@ environment:
dependencies:
flutter:
sdk: flutter
+ image: 4.5.4
plugin_platform_interface: 2.1.8
+ zxing2: 0.2.4
dev_dependencies:
flutter_lints: 6.0.0
@@ -23,7 +25,9 @@ flutter:
plugin:
platforms:
android:
- package: io.ente.photos.ente_qr
+ package: io.ente.ente_qr
pluginClass: EnteQrPlugin
ios:
pluginClass: EnteQrPlugin
+ macos:
+ pluginClass: EnteQrPlugin
diff --git a/mobile/packages/ente_qr/test/dart_zxing_qr_platform_test.dart b/mobile/packages/ente_qr/test/dart_zxing_qr_platform_test.dart
new file mode 100644
index 0000000000..74836c16e9
--- /dev/null
+++ b/mobile/packages/ente_qr/test/dart_zxing_qr_platform_test.dart
@@ -0,0 +1,73 @@
+import 'dart:io';
+
+import 'package:ente_qr/src/dart_zxing_qr_platform.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:image/image.dart' as img;
+import 'package:zxing2/qrcode.dart';
+
+void main() {
+ late Directory tempDir;
+
+ setUp(() async {
+ tempDir = await Directory.systemTemp.createTemp('ente_qr_test_');
+ });
+
+ tearDown(() async {
+ if (await tempDir.exists()) {
+ await tempDir.delete(recursive: true);
+ }
+ });
+
+ test('scanQrFromImage decodes a QR PNG', () async {
+ const payload =
+ 'otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example';
+ final imagePath = '${tempDir.path}/qr.png';
+ await File(imagePath).writeAsBytes(img.encodePng(_qrImage(payload)));
+
+ final result = await DartZxingQrPlatform().scanQrFromImage(imagePath);
+
+ expect(result.success, true);
+ expect(result.content, payload);
+ });
+
+ test('scanQrFromImage returns an error when no QR is present', () async {
+ final imagePath = '${tempDir.path}/blank.png';
+ final blank = img.Image(width: 320, height: 320)
+ ..clear(img.ColorRgb8(255, 255, 255));
+ await File(imagePath).writeAsBytes(img.encodePng(blank));
+
+ final result = await DartZxingQrPlatform().scanQrFromImage(imagePath);
+
+ expect(result.success, false);
+ expect(result.error, isNotEmpty);
+ });
+}
+
+img.Image _qrImage(String payload) {
+ final qrcode = Encoder.encode(payload, ErrorCorrectionLevel.h);
+ final matrix = qrcode.matrix!;
+ const pixelsPerModule = 8;
+ const quietZoneModules = 4;
+ final size = (matrix.width + quietZoneModules * 2) * pixelsPerModule;
+ final image = img.Image(width: size, height: size)
+ ..clear(img.ColorRgb8(255, 255, 255));
+
+ for (var y = 0; y < matrix.height; y++) {
+ for (var x = 0; x < matrix.width; x++) {
+ if (matrix.get(x, y) != 1) {
+ continue;
+ }
+ final left = (x + quietZoneModules) * pixelsPerModule;
+ final top = (y + quietZoneModules) * pixelsPerModule;
+ img.fillRect(
+ image,
+ x1: left,
+ y1: top,
+ x2: left + pixelsPerModule - 1,
+ y2: top + pixelsPerModule - 1,
+ color: img.ColorRgb8(0, 0, 0),
+ );
+ }
+ }
+ return image;
+}
diff --git a/mobile/apps/photos/plugins/ente_qr/test/ente_qr_test.dart b/mobile/packages/ente_qr/test/ente_qr_test.dart
similarity index 100%
rename from mobile/apps/photos/plugins/ente_qr/test/ente_qr_test.dart
rename to mobile/packages/ente_qr/test/ente_qr_test.dart