Skip to content

Commit

Permalink
feat: Now directly copying TOTP code when tapped on by search (if ena…
Browse files Browse the repository at this point in the history
…bled in the app settings).
  • Loading branch information
Skyost committed Nov 3, 2024
1 parent 7053b99 commit e1d2447
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,24 @@ class _HomePageState extends ConsumerState<HomePage> with BrightnessListener {
appBar: AppBar(
title: const TitleWidget(),
actions: [
_SearchButton(
onTotpFound: (totp) async {
TotpList totps = await ref.read(totpRepositoryProvider.future);
int index = totps.indexOf(totp);
if (index >= 0) {
itemScrollController.jumpTo(index: index);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
setState(() => emphasis = totp);
}
});
}
},
Builder(
builder: (context) => _SearchButton(
onTotpFound: (totp) async {
TotpList totps = await ref.read(totpRepositoryProvider.future);
int index = totps.indexOf(totp);
if (index >= 0) {
itemScrollController.jumpTo(index: index);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
setState(() => emphasis = totp);
}
});
}
if (!(await ref.read(displayCopyButtonSettingsEntryProvider.future)) && totp.isDecrypted && context.mounted) {
_HomePageBody._copyCode(context, totp as DecryptedTotp);
}
},
),
),
if (kDebugMode || currentPlatform != Platform.android)
IconButton(
Expand Down Expand Up @@ -285,7 +290,7 @@ class _HomePageBody extends ConsumerWidget {
}

/// Allows to copy the code to the clipboard.
Future<void> _copyCode(BuildContext context, DecryptedTotp totp) async {
static Future<void> _copyCode(BuildContext context, DecryptedTotp totp) async {
await Clipboard.setData(ClipboardData(text: totp.generateCode()));
if (context.mounted) {
SnackBarIcon.showSuccessSnackBar(context, text: translations.totp.actions.copyConfirmation);
Expand Down

0 comments on commit e1d2447

Please sign in to comment.