[auth] Add Appbar Lock Icon for Manual App Locking on Desktop + fix bugs (#3108)

## Description

When app lock is enabled on Auth's desktop app and when
closed/minimised, the app is not getting locked in certain cases. As a
workaround for that, have added a button to manually lock the app.
This commit is contained in:
Ashil
2024-09-10 15:06:39 +05:30
committed by GitHub
4 changed files with 60 additions and 7 deletions

View File

@@ -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"
}

View File

@@ -22,11 +22,15 @@ 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/utils/dialog_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_auth/utils/totp_util.dart';
@@ -199,6 +203,28 @@ class _HomePageState extends State<HomePage> {
}
}
Future<void> navigateToLockScreen() async {
final bool shouldShowLockScreen =
await Configuration.instance.shouldShowLockScreen();
if (shouldShowLockScreen) {
await AppLock.of(context)!.showLockScreen();
} else {
await showDialogWidget(
context: context,
title: context.l10n.appLockNotEnabled,
body: context.l10n.appLockNotEnabledDescription,
isDismissible: true,
buttons: const [
ButtonWidget(
buttonType: ButtonType.secondary,
labelText: "OK",
isInAlert: true,
),
],
);
}
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
@@ -251,8 +277,20 @@ class _HomePageState extends State<HomePage> {
),
focusNode: searchBoxFocusNode,
),
centerTitle: true,
centerTitle: PlatformUtil.isDesktop() ? false : true,
actions: <Widget>[
PlatformUtil.isDesktop()
? IconButton(
icon: const Icon(Icons.lock),
tooltip: l10n.appLock,
onPressed: () async {
await navigateToLockScreen();
},
)
: const SizedBox.shrink(),
const SizedBox(
width: 4,
),
IconButton(
icon: _showSearchBox
? const Icon(Icons.clear)

View File

@@ -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<LockScreenOptions> {
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();

View File

@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:math';
import 'package:ente_auth/core/configuration.dart';
@@ -193,6 +194,8 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
isCritical: true,
firstButtonOnTap: () async {
await UserService.instance.logout(context);
// To start the app afresh, resetting all state.
Process.killPid(pid, ProcessSignal.sigkill);
},
);
}