Skip to content

armgit / ente

Public Imported from GitHub
0

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

Option to scan image using native plugin

Neeraj Gupta5b3e996aaabb
diff --git a/mobile/apps/auth/ios/Podfile.lock b/mobile/apps/auth/ios/Podfile.lock
index 7893816108..6e4788a815 100644
--- a/mobile/apps/auth/ios/Podfile.lock
+++ b/mobile/apps/auth/ios/Podfile.lock
@@ -39,6 +39,8 @@ PODS:
- DKPhotoGallery/Resource (0.0.19):
- SDWebImage
- SwiftyGif
+ - ente_qr (0.0.1):
+ - Flutter
- file_picker (0.0.1):
- DKImagePickerController/PhotoGallery
- Flutter
@@ -136,6 +138,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_qr (from `.symlinks/plugins/ente_qr/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- file_saver (from `.symlinks/plugins/file_saver/ios`)
- fk_user_agent (from `.symlinks/plugins/fk_user_agent/ios`)
@@ -183,6 +186,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/cupertino_http/darwin"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
+ ente_qr:
+ :path: ".symlinks/plugins/ente_qr/ios"
file_picker:
:path: ".symlinks/plugins/file_picker/ios"
file_saver:
@@ -243,6 +248,7 @@ SPEC CHECKSUMS:
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
+ ente_qr: f39434aa69ea0e71047b49316365b2737f8a20aa
file_picker: b159e0c068aef54932bb15dc9fd1571818edaf49
file_saver: 503e386464dbe118f630e17b4c2e1190fa0cf808
fk_user_agent: 1f47ec39291e8372b1d692b50084b0d54103c545
diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dart
index ed4f9c6094..999379ee86 100644
--- a/mobile/apps/auth/lib/ui/home_page.dart
+++ b/mobile/apps/auth/lib/ui/home_page.dart
@@ -40,6 +40,7 @@ import 'package:ente_auth/utils/totp_util.dart';
import 'package:ente_events/event_bus.dart';
import 'package:ente_lock_screen/lock_screen_settings.dart';
import 'package:ente_lock_screen/ui/app_lock.dart';
+import 'package:ente_qr/ente_qr.dart';
import 'package:ente_ui/pages/base_home_page.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
@@ -52,7 +53,7 @@ import 'package:logging/logging.dart';
import 'package:move_to_background/move_to_background.dart';
import 'package:zxing2/qrcode.dart';
-class HomePage extends BaseHomePage {
+class HomePage extends BaseHomePage {
const HomePage({super.key});
@override
@@ -294,68 +295,128 @@ class _HomePageState extends State<HomePage> {
}
Future<void> _importFromGallery() async {
+ final l10n = AppLocalizations.of(context);
- final l10n = AppLocalizations.of(context);
-
- if (_isImportingFromGallery) {
- return;
- }
+ if (_isImportingFromGallery) {
+ return;
+ }
- setState(() {
- _isImportingFromGallery = true;
- });
+ setState(() {
+ _isImportingFromGallery = true;
+ });
- try {
- final FilePickerResult? result = await FilePicker.platform.pickFiles(
- type: FileType.image,
- );
+ try {
+ final FilePickerResult? result = await FilePicker.platform.pickFiles(
+ type: FileType.image,
+ );
- if (result == null || result.files.single.path == null) {
- return;
- }
+ if (result == null || result.files.single.path == null) {
+ return;
+ }
- final String imagePath = result.files.single.path!;
- final rawImage = await File(imagePath).readAsBytes();
- final image = img.decodeImage(rawImage);
+ final String imagePath = result.files.single.path!;
+ final rawImage = await File(imagePath).readAsBytes();
+ final image = img.decodeImage(rawImage);
- if (image == null) {
- await showErrorDialog(context, l10n.error, l10n.errorCouldNotReadImage);
- return;
- }
+ if (image == null) {
+ await showErrorDialog(context, l10n.error, l10n.errorCouldNotReadImage);
+ return;
+ }
- final source = RGBLuminanceSource(
- image.width, image.height,
- image.getBytes(order: img.ChannelOrder.rgba).buffer.asInt32List(),
- );
- final bitmap = BinaryBitmap(HybridBinarizer(source));
- final reader = QRCodeReader();
- final Result decodeResult = reader.decode(bitmap);
- final String code = decodeResult.text;
- try{
+ final source = RGBLuminanceSource(
+ image.width,
+ image.height,
+ image.getBytes(order: img.ChannelOrder.rgba).buffer.asInt32List(),
+ );
+ final bitmap = BinaryBitmap(HybridBinarizer(source));
+ final reader = QRCodeReader();
+ final Result decodeResult = reader.decode(bitmap);
+ final String code = decodeResult.text;
+ try {
final newCode = Code.fromOTPAuthUrl(code);
await CodeStore.instance.addCode(newCode, shouldSync: false);
- }
- catch (e){
+ } catch (e) {
await showErrorDialog(
- context, l10n.errorInvalidQRCode, l10n.errorInvalidQRCodeBody,
+ context,
+ l10n.errorInvalidQRCode,
+ l10n.errorInvalidQRCodeBody,
);
+ }
+ } on ReaderException {
+ showToast(context, l10n.errorNoQRCode);
+ } catch (e) {
+ await showErrorDialog(
+ context,
+ l10n.errorGenericTitle,
+ l10n.errorGenericBody,
+ );
+ } finally {
+ setState(() {
+ _isImportingFromGallery = false;
+ });
}
}
- on ReaderException {
- showToast(context, l10n.errorNoQRCode);
- }
- catch (e) {
- await showErrorDialog(
- context, l10n.errorGenericTitle, l10n.errorGenericBody,
- );
- }
- finally {
+ Future<void> _importFromGalleryNative() async {
+ final l10n = AppLocalizations.of(context);
+
+ if (_isImportingFromGallery) {
+ return;
+ }
+
setState(() {
- _isImportingFromGallery = false;
+ _isImportingFromGallery = true;
});
+
+ try {
+ final FilePickerResult? result = await FilePicker.platform.pickFiles(
+ type: FileType.image,
+ );
+
+ if (result == null || result.files.single.path == null) {
+ return;
+ }
+
+ final String imagePath = result.files.single.path!;
+ final enteQr = EnteQr();
+ final QrScanResult qrResult = await enteQr.scanQrFromImage(imagePath);
+
+ if (qrResult.success && qrResult.content != null) {
+ try {
+ final newCode = Code.fromOTPAuthUrl(qrResult.content!);
+ await CodeStore.instance.addCode(newCode, shouldSync: false);
+ // Focus the new code by searching
+ if ((_allCodes?.where((e) => !e.hasError).length ?? 0) > 2) {
+ _focusNewCode(newCode);
+ }
+ } catch (e) {
+ _logger.severe('Error adding code from QR scan', e);
+ await showErrorDialog(
+ context,
+ l10n.errorInvalidQRCode,
+ l10n.errorInvalidQRCodeBody,
+ );
+ }
+ } else {
+ _logger.warning('QR scan failed: ${qrResult.error}');
+ await showErrorDialog(
+ context,
+ l10n.errorNoQRCode,
+ qrResult.error ?? l10n.errorNoQRCode,
+ );
+ }
+ } catch (e) {
+ await showErrorDialog(
+ context,
+ l10n.errorGenericTitle,
+ l10n.errorGenericBody,
+ );
+ } finally {
+ setState(() {
+ _isImportingFromGallery = false;
+ });
+ }
}
-}
Future<void> _redirectToScannerPage() async {
final Code? code = await Navigator.of(context).push(
@@ -821,6 +882,14 @@ class _HomePageState extends State<HomePage> {
labelWidget: SpeedDialLabelWidget(context.l10n.importFromGallery),
onTap: _importFromGallery,
),
+ SpeedDialChild(
+ child: const Icon(Icons.photo_library),
+ backgroundColor: Theme.of(context).colorScheme.fabBackgroundColor,
+ foregroundColor: Theme.of(context).colorScheme.fabForegroundColor,
+ labelWidget:
+ const SpeedDialLabelWidget("Import from Gallery (Native)"),
+ onTap: _importFromGalleryNative,
+ ),
],
);
}
diff --git a/mobile/apps/auth/plugins/qr/.metadata b/mobile/apps/auth/plugins/qr/.metadata
new file mode 100644
index 0000000000..458e07f485
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/.metadata
@@ -0,0 +1,33 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled and should not be manually edited.
+
+version:
+ revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49"
+ channel: "stable"
+
+project_type: plugin
+
+# Tracks metadata for the flutter migrate command
+migration:
+ platforms:
+ - platform: root
+ create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
+ base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
+ - platform: android
+ create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
+ base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
+ - platform: ios
+ create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
+ base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
+
+ # User provided section
+
+ # List of Local paths (relative to this file) that should be
+ # ignored by the migrate tool.
+ #
+ # Files that are not part of the templates will be ignored by default.
+ unmanaged_files:
+ - 'lib/main.dart'
+ - 'ios/Runner.xcodeproj/project.pbxproj'
diff --git a/mobile/apps/auth/plugins/qr/CHANGELOG.md b/mobile/apps/auth/plugins/qr/CHANGELOG.md
new file mode 100644
index 0000000000..b5e7771fe5
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/CHANGELOG.md
@@ -0,0 +1,8 @@
+## 0.0.1
+
+* 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
+* 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
new file mode 100644
index 0000000000..741fdc38bb
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/README.md
@@ -0,0 +1,170 @@
+# 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.
+
+## 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_qr:
+ path: path/to/ente_qr
+```
+
+## Usage
+
+### Basic Usage
+
+```dart
+import 'package:ente_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_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/analysis_options.yaml b/mobile/apps/auth/plugins/qr/analysis_options.yaml
new file mode 100644
index 0000000000..ec06379686
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/analysis_options.yaml
@@ -0,0 +1 @@
+include: ../../../../analysis_options.yaml
diff --git a/mobile/apps/auth/plugins/qr/android/build.gradle b/mobile/apps/auth/plugins/qr/android/build.gradle
new file mode 100644
index 0000000000..39a44b6686
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/android/build.gradle
@@ -0,0 +1,65 @@
+group 'io.ente.auth.ente_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 {
+ compileSdkVersion 33
+
+ 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
new file mode 100644
index 0000000000..89b0daf645
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/android/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'ente_qr'
diff --git a/mobile/apps/auth/plugins/qr/android/src/main/AndroidManifest.xml b/mobile/apps/auth/plugins/qr/android/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..ad0e4b4e06
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/android/src/main/AndroidManifest.xml
@@ -0,0 +1,3 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="io.ente.auth.ente_qr">
+</manifest>
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.kt
new file mode 100644
index 0000000000..367f585a9f
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/android/src/main/kotlin/io/ente/auth/ente_qr/EnteQrPlugin.kt
@@ -0,0 +1,113 @@
+package io.ente.auth.ente_qr
+
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import androidx.annotation.NonNull
+import com.google.zxing.BinaryBitmap
+import com.google.zxing.DecodeHintType
+import com.google.zxing.MultiFormatReader
+import com.google.zxing.RGBLuminanceSource
+import com.google.zxing.Result
+import com.google.zxing.common.HybridBinarizer
+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.*
+
+/** 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 Activity
+ private lateinit var channel : MethodChannel
+
+ 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
+ }
+
+ 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}"
+ ))
+ }
+ }
+ 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"
+ )
+ }
+
+ val bitmap = BitmapFactory.decodeFile(imagePath)
+ if (bitmap == null) {
+ return mapOf(
+ "success" to false,
+ "error" to "Unable to decode image file"
+ )
+ }
+
+ 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 = EnumMap<DecodeHintType, Any>(DecodeHintType::class.java)
+ hints[DecodeHintType.TRY_HARDER] = true
+ hints[DecodeHintType.PURE_BARCODE] = false
+ reader.setHints(hints)
+
+ val qrResult: Result = reader.decode(binaryBitmap)
+
+ return mapOf(
+ "success" to true,
+ "content" to qrResult.text
+ )
+ } catch (e: Exception) {
+ return mapOf(
+ "success" to false,
+ "error" to "No QR code found in image or unable to read: ${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
new file mode 100644
index 0000000000..6a03563511
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/ios/Classes/EnteQrPlugin.swift
@@ -0,0 +1,77 @@
+import Flutter
+import UIKit
+import AVFoundation
+
+public class EnteQrPlugin: NSObject, FlutterPlugin {
+ 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)
+ default:
+ result(FlutterMethodNotImplemented)
+ }
+ }
+
+ private func scanQrCode(from imagePath: String, result: @escaping FlutterResult) {
+ guard let image = UIImage(contentsOfFile: imagePath) else {
+ result([
+ "success": false,
+ "error": "Unable to load image from path: \(imagePath)"
+ ])
+ return
+ }
+
+ guard let cgImage = image.cgImage else {
+ 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 {
+ 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 {
+ result([
+ "success": true,
+ "content": messageString
+ ])
+ } else {
+ result([
+ "success": false,
+ "error": "No QR code found in image"
+ ])
+ }
+ }
+}
diff --git a/mobile/apps/auth/plugins/qr/ios/ente_qr.podspec b/mobile/apps/auth/plugins/qr/ios/ente_qr.podspec
new file mode 100644
index 0000000000..9c12badcec
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/ios/ente_qr.podspec
@@ -0,0 +1,23 @@
+#
+# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
+# Run `pod lib lint ente_qr.podspec` to validate before publishing.
+#
+Pod::Spec.new do |s|
+ s.name = 'ente_qr'
+ s.version = '0.0.1'
+ s.summary = 'A QR code reader plugin for Ente.'
+ s.description = <<-DESC
+A QR code reader plugin for Ente.
+ DESC
+ s.homepage = 'https://ente.io'
+ s.license = { :file => '../LICENSE' }
+ s.author = { 'Ente' => '[email protected]' }
+ s.source = { :path => '.' }
+ s.source_files = 'Classes/**/*'
+ s.dependency 'Flutter'
+ 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' }
+ s.swift_version = '5.0'
+end
diff --git a/mobile/apps/auth/plugins/qr/lib/ente_qr.dart b/mobile/apps/auth/plugins/qr/lib/ente_qr.dart
new file mode 100644
index 0000000000..d58544c930
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/lib/ente_qr.dart
@@ -0,0 +1,30 @@
+import 'package:ente_qr/ente_qr_platform_interface.dart';
+
+export 'ente_qr_platform_interface.dart' show QrScanResult;
+
+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.
+ ///
+ /// Example:
+ /// ```dart
+ /// final qr = EnteQr();
+ /// final result = await qr.scanQrFromImage('/path/to/image.jpg');
+ /// if (result.success) {
+ /// print('QR Code content: ${result.content}');
+ /// } else {
+ /// print('Error: ${result.error}');
+ /// }
+ /// ```
+ Future<QrScanResult> scanQrFromImage(String imagePath) {
+ return EnteQrPlatform.instance.scanQrFromImage(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
new file mode 100644
index 0000000000..d8542a7309
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/lib/ente_qr_method_channel.dart
@@ -0,0 +1,51 @@
+import 'package:ente_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');
+ }
+ }
+}
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
new file mode 100644
index 0000000000..4b870368e7
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/lib/ente_qr_platform_interface.dart
@@ -0,0 +1,61 @@
+import 'package:ente_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,
+ );
+ }
+}
+
+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.');
+ }
+}
diff --git a/mobile/apps/auth/plugins/qr/pubspec.lock b/mobile/apps/auth/plugins/qr/pubspec.lock
new file mode 100644
index 0000000000..af5aa0bcd5
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/pubspec.lock
@@ -0,0 +1,213 @@
+# Generated by pub
+# See https://dart.dev/tools/pub/glossary#lockfile
+packages:
+ async:
+ dependency: transitive
+ description:
+ name: async
+ sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.13.0"
+ 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: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.2"
+ flutter_test:
+ dependency: "direct dev"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ leak_tracker:
+ dependency: transitive
+ description:
+ name: leak_tracker
+ sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
+ url: "https://pub.dev"
+ source: hosted
+ version: "10.0.9"
+ leak_tracker_flutter_testing:
+ dependency: transitive
+ description:
+ name: leak_tracker_flutter_testing
+ sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.9"
+ leak_tracker_testing:
+ dependency: transitive
+ description:
+ name: leak_tracker_testing
+ sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.1"
+ lints:
+ dependency: transitive
+ description:
+ name: lints
+ sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.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: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.16.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: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.10.1"
+ 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: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.7.4"
+ vector_math:
+ dependency: transitive
+ description:
+ name: vector_math
+ sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.1.4"
+ vm_service:
+ dependency: transitive
+ description:
+ name: vm_service
+ sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
+ url: "https://pub.dev"
+ source: hosted
+ version: "15.0.0"
+sdks:
+ dart: ">=3.7.0-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
new file mode 100644
index 0000000000..dada764451
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/pubspec.yaml
@@ -0,0 +1,29 @@
+name: ente_qr
+description: "A QR code reader plugin for Ente."
+version: 0.0.1
+homepage: https://ente.io
+
+environment:
+ sdk: '>=3.4.3 <4.0.0'
+ flutter: '>=3.3.0'
+
+dependencies:
+ flutter:
+ sdk: flutter
+ plugin_platform_interface: ^2.0.2
+
+dev_dependencies:
+ flutter_lints: ^3.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_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
new file mode 100644
index 0000000000..665f225ef4
--- /dev/null
+++ b/mobile/apps/auth/plugins/qr/test/ente_qr_test.dart
@@ -0,0 +1,33 @@
+import 'package:ente_qr/ente_qr.dart';
+import 'package:ente_qr/ente_qr_method_channel.dart';
+import 'package:ente_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'));
+}
+
+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 e869ebebc6..5b4e282cc3 100644
--- a/mobile/apps/auth/pubspec.lock
+++ b/mobile/apps/auth/pubspec.lock
@@ -459,6 +459,13 @@ packages:
relative: true
source: path
version: "1.0.0"
+ ente_qr:
+ dependency: "direct main"
+ description:
+ path: "plugins/qr"
+ relative: true
+ source: path
+ version: "0.0.1"
ente_strings:
dependency: "direct main"
description:
diff --git a/mobile/apps/auth/pubspec.yaml b/mobile/apps/auth/pubspec.yaml
index 89c6908f19..c349a510af 100644
--- a/mobile/apps/auth/pubspec.yaml
+++ b/mobile/apps/auth/pubspec.yaml
@@ -41,6 +41,8 @@ dependencies:
path: ../../packages/logging
ente_network:
path: ../../packages/network
+ ente_qr:
+ path: plugins/qr
ente_strings:
path: ../../packages/strings
ente_ui: