π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth] implemented import code from images having qr_code
Aman Raj548b4e7a0895
diff --git a/auth/lib/ui/home/home_empty_state.dart b/auth/lib/ui/home/home_empty_state.dartindex 68d9044aa6..0ed6ebcda9 100644--- a/auth/lib/ui/home/home_empty_state.dart+++ b/auth/lib/ui/home/home_empty_state.dart@@ -9,11 +9,13 @@ import 'package:logging/logging.dart';class HomeEmptyStateWidget extends StatelessWidget {final VoidCallback? onScanTap;final VoidCallback? onManuallySetupTap;+ final VoidCallback? onImportFromGallery;const HomeEmptyStateWidget({super.key,required this.onScanTap,required this.onManuallySetupTap,+ this.onImportFromGallery,});@override@@ -50,6 +52,15 @@ class HomeEmptyStateWidget extends StatelessWidget {),),const SizedBox(height: 18),+ if (PlatformUtil.isMobile())+ SizedBox(+ width: 400,+ child: OutlinedButton(+ onPressed: onImportFromGallery,+ child: const Text("Import from gallery"),+ ),+ ),+ const SizedBox(height: 18),SizedBox(width: 400,child: OutlinedButton(diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dartindex 1a2d0a83a7..e6e4314f2a 100644--- a/auth/lib/ui/home_page.dart+++ b/auth/lib/ui/home_page.dart@@ -36,6 +36,7 @@ import 'package:ente_auth/ui/tools/app_lock.dart';import 'package:ente_auth/utils/dialog_util.dart';import 'package:ente_auth/utils/platform_util.dart';import 'package:ente_auth/utils/totp_util.dart';+import 'package:file_picker/file_picker.dart';import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';import 'package:flutter/services.dart';@@ -43,6 +44,7 @@ import 'package:flutter_speed_dial/flutter_speed_dial.dart';import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';import 'package:logging/logging.dart';import 'package:move_to_background/move_to_background.dart';+import 'package:scan/scan.dart';class HomePage extends StatefulWidget {const HomePage({super.key});@@ -442,6 +444,7 @@ class _HomePageState extends State<HomePage> {return HomeEmptyStateWidget(onScanTap: _redirectToScannerPage,onManuallySetupTap: _redirectToManualEntryPage,+ onImportFromGallery: _importFromGallery,);} else {final anyCodeHasError =@@ -657,6 +660,29 @@ class _HomePageState extends State<HomePage> {_applyFilteringAndRefresh();}+ Future<void> _importFromGallery() async {+ try {+ final FilePickerResult? result = await FilePicker.platform.pickFiles(+ type: FileType.image,+ allowMultiple: false,+ );+ if (result != null) {+ final path = result.files.single.path!;+ String? res = await Scan.parse(path);+ final Code? code = res != null ? Code.fromOTPAuthUrl(res) : null;+ if (code != null) {+ await CodeStore.instance.addCode(code);+ if ((_allCodes?.where((e) => !e.hasError).length ?? 0) > 2) {+ _focusNewCode(code);+ }+ }+ }+ } catch (e, s) {+ await showGenericErrorDialog(context: context, error: e);+ _logger.severe("Error while importing from gallery", e, s);+ }+ }+Widget _getFab() {if (PlatformUtil.isDesktop()) {return FloatingActionButton(@@ -687,6 +713,14 @@ class _HomePageState extends State<HomePage> {labelWidget: SpeedDialLabelWidget(context.l10n.scanAQrCode),onTap: _redirectToScannerPage,),+ if (PlatformUtil.isMobile())+ SpeedDialChild(+ child: const Icon(Icons.image),+ foregroundColor: Theme.of(context).colorScheme.fabForegroundColor,+ backgroundColor: Theme.of(context).colorScheme.fabBackgroundColor,+ labelWidget: const SpeedDialLabelWidget("Import from gallery"),+ onTap: _importFromGallery,+ ),SpeedDialChild(child: const Icon(Icons.keyboard),foregroundColor: Theme.of(context).colorScheme.fabForegroundColor,