Support for masking codes (#267)

This commit is contained in:
Neeraj Gupta 2023-09-29 14:06:21 +05:30 committed by GitHub
commit 9198b3c29a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 2 deletions

View file

@ -330,5 +330,6 @@
"sigInBackupReminder": "Please export your codes to ensure that you have a backup you can restore from.",
"offlineModeWarning": "You have chosen to proceed without backups. Please take manual backups to make sure your codes are safe.",
"showLargeIcons": "Show large icons",
"shouldHideCode": "Hide codes",
"focusOnSearchBar": "Focus search on app start"
}

View file

@ -11,6 +11,7 @@ class PreferenceService {
static const kHasShownCoachMarkKey = "has_shown_coach_mark";
static const kShouldShowLargeIconsKey = "should_show_large_icons";
static const kShouldHideCodesKey = "should_hide_codes";
static const kShouldAutoFocusOnSearchBar = "should_auto_focus_on_search_bar";
Future<void> init() async {
@ -42,6 +43,15 @@ class PreferenceService {
Bus.instance.fire(IconsChangedEvent());
}
bool shouldHideCodes() {
return _prefs.getBool(kShouldHideCodesKey) ?? false;
}
Future<void> setHideCodes(bool value) async {
await _prefs.setBool(kShouldHideCodesKey, value);
Bus.instance.fire(IconsChangedEvent());
}
bool shouldAutoFocusOnSearchBar() {
if (_prefs.containsKey(kShouldAutoFocusOnSearchBar)) {
return _prefs.getBool(kShouldAutoFocusOnSearchBar)!;

View file

@ -35,11 +35,14 @@ class _CodeWidgetState extends State<CodeWidget> {
bool _isInitialized = false;
late bool hasConfiguredAccount;
late bool _shouldShowLargeIcon;
late bool _hideCode;
bool isMaskingEnabled = false;
@override
void initState() {
super.initState();
isMaskingEnabled = PreferenceService.instance.shouldHideCodes();
_hideCode = isMaskingEnabled;
_everySecondTimer =
Timer.periodic(const Duration(milliseconds: 500), (Timer t) {
String newCode = _getCurrentOTP();
@ -63,6 +66,10 @@ class _CodeWidgetState extends State<CodeWidget> {
@override
Widget build(BuildContext context) {
if (isMaskingEnabled != PreferenceService.instance.shouldHideCodes()) {
isMaskingEnabled = PreferenceService.instance.shouldHideCodes();
_hideCode = isMaskingEnabled;
}
_shouldShowLargeIcon = PreferenceService.instance.shouldShowLargeIcons();
if (!_isInitialized) {
_currentCode.value = _getCurrentOTP();
@ -136,6 +143,15 @@ class _CodeWidgetState extends State<CodeWidget> {
onTap: () {
_copyToClipboard();
},
onDoubleTap: isMaskingEnabled
? () {
setState(
() {
_hideCode = !_hideCode;
},
);
}
: null,
onLongPress: () {
_copyToClipboard();
},
@ -390,6 +406,10 @@ class _CodeWidgetState extends State<CodeWidget> {
}
String _getFormattedCode(String code) {
if (_hideCode) {
// replace all digits with
code = code.replaceAll(RegExp(r'\d'), '');
}
if (code.length == 6) {
return code.substring(0, 3) + " " + code.substring(3, 6);
}

View file

@ -74,6 +74,21 @@ class _AdvancedSectionWidgetState extends State<AdvancedSectionWidget> {
),
),
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: l10n.shouldHideCode,
),
trailingWidget: ToggleSwitchWidget(
value: () => PreferenceService.instance.shouldHideCodes(),
onChanged: () async {
await PreferenceService.instance.setHideCodes(
!PreferenceService.instance.shouldHideCodes(),
);
setState(() {});
},
),
),
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: l10n.focusOnSearchBar,

View file

@ -1,6 +1,6 @@
name: ente_auth
description: ente two-factor authenticator
version: 2.0.4+204
version: 2.0.5+205
publish_to: none
environment: