From d139d23c21bc7d35e08d263e38d6fb00086cb0ff Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Tue, 3 Sep 2024 14:24:41 +0530 Subject: [PATCH 1/7] [auth] Lock icon to manually lock app on desktop --- auth/lib/ui/home_page.dart | 36 +++++++++++++++++++ .../lock_screen/lock_screen_options.dart | 20 ++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart index f9c6410d9d..1c47c17ae8 100644 --- a/auth/lib/ui/home_page.dart +++ b/auth/lib/ui/home_page.dart @@ -22,11 +22,16 @@ import 'package:ente_auth/ui/account/logout_dialog.dart'; import 'package:ente_auth/ui/code_error_widget.dart'; import 'package:ente_auth/ui/code_widget.dart'; import 'package:ente_auth/ui/common/loading_widget.dart'; +import 'package:ente_auth/ui/components/buttons/button_widget.dart'; +import 'package:ente_auth/ui/components/dialog_widget.dart'; +import 'package:ente_auth/ui/components/models/button_type.dart'; import 'package:ente_auth/ui/home/coach_mark_widget.dart'; import 'package:ente_auth/ui/home/home_empty_state.dart'; import 'package:ente_auth/ui/home/speed_dial_label_widget.dart'; import 'package:ente_auth/ui/scanner_page.dart'; import 'package:ente_auth/ui/settings_page.dart'; +import 'package:ente_auth/ui/tools/app_lock.dart'; +// import 'package:ente_auth/ui/tools/lock_screen.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'; @@ -199,6 +204,28 @@ class _HomePageState extends State { } } + Future navigateToLockScreen() async { + final bool shouldShowLockScreen = + await Configuration.instance.shouldShowLockScreen(); + if (shouldShowLockScreen) { + await AppLock.of(context)!.showLockScreen(); + } else { + await showDialogWidget( + context: context, + title: "No app lock enabled", + body: "Please enable app lock from Security > App Lock", + isDismissible: true, + buttons: const [ + ButtonWidget( + buttonType: ButtonType.secondary, + labelText: "OK", + isInAlert: true, + ), + ], + ); + } + } + @override Widget build(BuildContext context) { final l10n = context.l10n; @@ -279,6 +306,15 @@ class _HomePageState extends State { ); }, ), + PlatformUtil.isDesktop() + ? IconButton( + icon: const Icon(Icons.lock), + tooltip: l10n.appLock, + onPressed: () async { + await navigateToLockScreen(); + }, + ) + : const SizedBox.shrink(), ], ), floatingActionButton: !_hasLoaded || diff --git a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart index b055a94f1d..9f53f10248 100644 --- a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart +++ b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart @@ -5,9 +5,12 @@ import "package:ente_auth/core/configuration.dart"; import "package:ente_auth/l10n/l10n.dart"; import "package:ente_auth/services/local_authentication_service.dart"; import "package:ente_auth/theme/ente_theme.dart"; +import "package:ente_auth/ui/components/buttons/button_widget.dart"; import "package:ente_auth/ui/components/captioned_text_widget.dart"; +import "package:ente_auth/ui/components/dialog_widget.dart"; import "package:ente_auth/ui/components/divider_widget.dart"; import "package:ente_auth/ui/components/menu_item_widget.dart"; +import "package:ente_auth/ui/components/models/button_type.dart"; import "package:ente_auth/ui/components/title_bar_title_widget.dart"; import "package:ente_auth/ui/components/title_bar_widget.dart"; import "package:ente_auth/ui/components/toggle_switch_widget.dart"; @@ -15,7 +18,6 @@ import "package:ente_auth/ui/settings/lock_screen/lock_screen_auto_lock.dart"; import "package:ente_auth/ui/settings/lock_screen/lock_screen_password.dart"; import "package:ente_auth/ui/settings/lock_screen/lock_screen_pin.dart"; import "package:ente_auth/ui/tools/app_lock.dart"; -import "package:ente_auth/utils/dialog_util.dart"; import "package:ente_auth/utils/lock_screen_settings.dart"; import "package:ente_auth/utils/navigation_util.dart"; import "package:ente_auth/utils/platform_util.dart"; @@ -67,10 +69,18 @@ class _LockScreenOptionsState extends State { await _lockscreenSetting.removePinAndPassword(); await _configuration.setSystemLockScreen(!isSystemLockEnabled); } else { - await showErrorDialog( - context, - context.l10n.noSystemLockFound, - context.l10n.deviceLockEnablePreSteps, + await showDialogWidget( + context: context, + title: context.l10n.noSystemLockFound, + body: context.l10n.deviceLockEnablePreSteps, + isDismissible: true, + buttons: const [ + ButtonWidget( + buttonType: ButtonType.secondary, + labelText: "OK", + isInAlert: true, + ), + ], ); } await _initializeSettings(); From 0b5e057e4e7a5c47e8a2716ae0e94346ece44216 Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Tue, 3 Sep 2024 15:20:17 +0530 Subject: [PATCH 2/7] [auth] Changed location of lock icon --- auth/lib/ui/home_page.dart | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart index 1c47c17ae8..f480365172 100644 --- a/auth/lib/ui/home_page.dart +++ b/auth/lib/ui/home_page.dart @@ -31,7 +31,6 @@ import 'package:ente_auth/ui/home/speed_dial_label_widget.dart'; import 'package:ente_auth/ui/scanner_page.dart'; import 'package:ente_auth/ui/settings_page.dart'; import 'package:ente_auth/ui/tools/app_lock.dart'; -// import 'package:ente_auth/ui/tools/lock_screen.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'; @@ -278,8 +277,17 @@ class _HomePageState extends State { ), focusNode: searchBoxFocusNode, ), - centerTitle: true, + centerTitle: PlatformUtil.isDesktop() ? false : true, actions: [ + PlatformUtil.isDesktop() + ? IconButton( + icon: const Icon(Icons.lock), + tooltip: l10n.appLock, + onPressed: () async { + await navigateToLockScreen(); + }, + ) + : const SizedBox.shrink(), IconButton( icon: _showSearchBox ? const Icon(Icons.clear) @@ -306,15 +314,6 @@ class _HomePageState extends State { ); }, ), - PlatformUtil.isDesktop() - ? IconButton( - icon: const Icon(Icons.lock), - tooltip: l10n.appLock, - onPressed: () async { - await navigateToLockScreen(); - }, - ) - : const SizedBox.shrink(), ], ), floatingActionButton: !_hasLoaded || From 9afb59ea87795a496377b4455c5ac81a5b23594d Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Wed, 4 Sep 2024 21:46:33 +0530 Subject: [PATCH 3/7] [auth] Extract strings --- auth/lib/l10n/arb/app_en.arb | 4 +++- auth/lib/ui/home_page.dart | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/auth/lib/l10n/arb/app_en.arb b/auth/lib/l10n/arb/app_en.arb index 06b5e42c44..3b0f8a7139 100644 --- a/auth/lib/l10n/arb/app_en.arb +++ b/auth/lib/l10n/arb/app_en.arb @@ -466,5 +466,7 @@ "pinLock": "Pin lock", "enterPin": "Enter PIN", "setNewPin": "Set new PIN", - "importFailureDescNew": "Could not parse the selected file." + "importFailureDescNew": "Could not parse the selected file.", + "appLockNotEnabled": "App lock not enabled", + "appLockNotEnabledDescription": "Please enable app lock from Security > App Lock" } \ No newline at end of file diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart index f480365172..f2c5222da3 100644 --- a/auth/lib/ui/home_page.dart +++ b/auth/lib/ui/home_page.dart @@ -211,8 +211,8 @@ class _HomePageState extends State { } else { await showDialogWidget( context: context, - title: "No app lock enabled", - body: "Please enable app lock from Security > App Lock", + title: context.l10n.appLockNotEnabled, + body: context.l10n.appLockNotEnabledDescription, isDismissible: true, buttons: const [ ButtonWidget( From 76a1423e720687a6a7517b6f88aea33d183d4e9d Mon Sep 17 00:00:00 2001 From: ashilkn Date: Fri, 6 Sep 2024 14:50:45 +0530 Subject: [PATCH 4/7] [auth] Add space between lock and search icon --- auth/lib/ui/home_page.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart index f2c5222da3..718b20662f 100644 --- a/auth/lib/ui/home_page.dart +++ b/auth/lib/ui/home_page.dart @@ -288,6 +288,9 @@ class _HomePageState extends State { }, ) : const SizedBox.shrink(), + const SizedBox( + width: 4, + ), IconButton( icon: _showSearchBox ? const Icon(Icons.clear) From ba270000b2a40e189d4da3c3d9d12ee1658dacca Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Tue, 10 Sep 2024 12:52:27 +0530 Subject: [PATCH 5/7] [auth] Fix logout action --- auth/lib/ui/tools/lock_screen.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/auth/lib/ui/tools/lock_screen.dart b/auth/lib/ui/tools/lock_screen.dart index a77ba6d155..139a7fcbd2 100644 --- a/auth/lib/ui/tools/lock_screen.dart +++ b/auth/lib/ui/tools/lock_screen.dart @@ -3,12 +3,14 @@ import 'dart:math'; import 'package:ente_auth/core/configuration.dart'; import 'package:ente_auth/l10n/l10n.dart'; +import 'package:ente_auth/onboarding/view/onboarding_page.dart'; import 'package:ente_auth/services/user_service.dart'; import 'package:ente_auth/theme/ente_theme.dart'; import 'package:ente_auth/ui/tools/app_lock.dart'; import 'package:ente_auth/utils/auth_util.dart'; import 'package:ente_auth/utils/dialog_util.dart'; import 'package:ente_auth/utils/lock_screen_settings.dart'; +import 'package:ente_auth/utils/navigation_util.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_animate/flutter_animate.dart'; @@ -206,6 +208,10 @@ class _LockScreenState extends State with WidgetsBindingObserver { isCritical: true, firstButtonOnTap: () async { await UserService.instance.logout(context); + await routeToPage( + context, + const OnboardingPage(), + ); }, ); } From acdd38743cbf922104c43e7331662792d2249ed0 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 10 Sep 2024 14:54:00 +0530 Subject: [PATCH 6/7] [mob][photos] Kill app so that the app starts afresh after logging out from the lockscreen --- auth/lib/ui/tools/lock_screen.dart | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/auth/lib/ui/tools/lock_screen.dart b/auth/lib/ui/tools/lock_screen.dart index 3fcb76a38a..b66472f5af 100644 --- a/auth/lib/ui/tools/lock_screen.dart +++ b/auth/lib/ui/tools/lock_screen.dart @@ -1,15 +1,14 @@ +import 'dart:io'; import 'dart:math'; import 'package:ente_auth/core/configuration.dart'; import 'package:ente_auth/l10n/l10n.dart'; -import 'package:ente_auth/onboarding/view/onboarding_page.dart'; import 'package:ente_auth/services/user_service.dart'; import 'package:ente_auth/theme/ente_theme.dart'; import 'package:ente_auth/ui/tools/app_lock.dart'; import 'package:ente_auth/utils/auth_util.dart'; import 'package:ente_auth/utils/dialog_util.dart'; import 'package:ente_auth/utils/lock_screen_settings.dart'; -import 'package:ente_auth/utils/navigation_util.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_animate/flutter_animate.dart'; @@ -195,10 +194,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { isCritical: true, firstButtonOnTap: () async { await UserService.instance.logout(context); - await routeToPage( - context, - const OnboardingPage(), - ); + Process.killPid(pid, ProcessSignal.sigkill); }, ); } From b2e9b242ad3e4aef03960927d03aa006764481b6 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 10 Sep 2024 15:00:55 +0530 Subject: [PATCH 7/7] [mob][photos] Add comment --- auth/lib/ui/tools/lock_screen.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/auth/lib/ui/tools/lock_screen.dart b/auth/lib/ui/tools/lock_screen.dart index b66472f5af..3793230798 100644 --- a/auth/lib/ui/tools/lock_screen.dart +++ b/auth/lib/ui/tools/lock_screen.dart @@ -194,6 +194,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { isCritical: true, firstButtonOnTap: () async { await UserService.instance.logout(context); + // To start the app afresh, resetting all state. Process.killPid(pid, ProcessSignal.sigkill); }, );