Skip to content

Commit

Permalink
fix: local auth refocus windows
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia committed Feb 19, 2024
1 parent e54ce2f commit 1d13814
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/ui/account/delete_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:ente_auth/services/user_service.dart';
import 'package:ente_auth/ui/common/dialogs.dart';
import 'package:ente_auth/ui/common/gradient_button.dart';
import 'package:ente_auth/utils/email_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -149,8 +150,9 @@ class DeleteAccountPage extends StatelessWidget {
l10n.initiateAccountDeleteTitle,
);

await PlatformUtil.refocusWindows();

if (hasAuthenticated) {
FocusScope.of(context).requestFocus();
final choice = await showChoiceDialogOld(
context,
l10n.confirmAccountDeleteTitle,
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/account/verify_recovery_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:ente_auth/ui/common/gradient_button.dart';
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/navigation_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -88,8 +89,9 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
context,
"Please authenticate to view your recovery key",
);
await PlatformUtil.refocusWindows();

if (hasAuthenticated) {
FocusScope.of(context).requestFocus();
String recoveryKey;
try {
recoveryKey =
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/code_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/ui/code_timer_progress.dart';
import 'package:ente_auth/ui/utils/icon_utils.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_auth/utils/totp_util.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -374,10 +375,10 @@ class _CodeWidgetState extends State<CodeWidget> {
Future<void> _onEditPressed(_) async {
bool isAuthSuccessful = await LocalAuthenticationService.instance
.requestLocalAuthentication(context, context.l10n.editCodeAuthMessage);
await PlatformUtil.refocusWindows();
if (!isAuthSuccessful) {
return;
}
FocusScope.of(context).requestFocus();
final Code? code = await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
Expand All @@ -393,10 +394,10 @@ class _CodeWidgetState extends State<CodeWidget> {
Future<void> _onShowQrPressed(_) async {
bool isAuthSuccessful = await LocalAuthenticationService.instance
.requestLocalAuthentication(context, context.l10n.showQRAuthMessage);
await PlatformUtil.refocusWindows();
if (!isAuthSuccessful) {
return;
}
FocusScope.of(context).requestFocus();
// ignore: unused_local_variable
final Code? code = await Navigator.of(context).push(
MaterialPageRoute(
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/settings/account_section_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:ente_auth/ui/components/menu_item_widget.dart';
import 'package:ente_auth/ui/settings/common_settings.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/navigation_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:flutter/material.dart';

class AccountSectionWidget extends StatelessWidget {
Expand Down Expand Up @@ -43,8 +44,8 @@ class AccountSectionWidget extends StatelessWidget {
context,
l10n.authToChangeYourEmail,
);
await PlatformUtil.refocusWindows();
if (hasAuthenticated) {
FocusScope.of(context).requestFocus();
showDialog(
context: context,
builder: (BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/settings/data/export_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ Future<void> _exportCodes(BuildContext context, String fileContent) async {
String exportFileExtension = 'txt';
final hasAuthenticated = await LocalAuthenticationService.instance
.requestLocalAuthentication(context, context.l10n.authToExportCodes);
await PlatformUtil.refocusWindows();
if (!hasAuthenticated) {
return;
}
FocusScope.of(context).requestFocus();
Future.delayed(
const Duration(milliseconds: 1200),
() async => await shareDialog(
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/settings/security_section_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:ente_auth/ui/components/toggle_switch_widget.dart';
import 'package:ente_auth/ui/settings/common_settings.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/navigation_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -77,8 +78,8 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
context,
l10n.authToViewYourRecoveryKey,
);
await PlatformUtil.refocusWindows();
if (hasAuthenticated) {
FocusScope.of(context).requestFocus();
String recoveryKey;
try {
recoveryKey =
Expand Down Expand Up @@ -113,8 +114,8 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
);
final isEmailMFAEnabled =
UserService.instance.hasEmailMFAEnabled();
await PlatformUtil.refocusWindows();
if (hasAuthenticated) {
FocusScope.of(context).requestFocus();
await updateEmailMFA(!isEmailMFAEnabled);
if (mounted) {
setState(() {});
Expand All @@ -137,8 +138,8 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
context,
context.l10n.authToViewYourActiveSessions,
);
await PlatformUtil.refocusWindows();
if (hasAuthenticated) {
FocusScope.of(context).requestFocus();
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:ente_auth/ui/settings/theme_switch_widget.dart';
import 'package:ente_auth/ui/settings/title_bar_widget.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/navigation_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -115,11 +116,11 @@ class SettingsPage extends StatelessWidget {
context,
context.l10n.authToInitiateSignIn,
);
await PlatformUtil.refocusWindows();
if (!hasAuthenticated) {
return;
}
}
FocusScope.of(context).requestFocus();
await routeToPage(
context,
const OnboardingPage(),
Expand Down
11 changes: 11 additions & 0 deletions lib/utils/platform_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:window_manager/window_manager.dart';

class PlatformUtil {
static bool isDesktop() {
Expand Down Expand Up @@ -79,4 +80,14 @@ class PlatformUtil {
}
} catch (e) {}
}

// Needed to fix issue with local_auth on Windows
// https://github.com/flutter/flutter/issues/122322
static Future<void> refocusWindows() async {
if (!Platform.isWindows) return;
await windowManager.blur();
await windowManager.focus();
await windowManager.setAlwaysOnTop(true);
await windowManager.setAlwaysOnTop(false);
}
}

0 comments on commit 1d13814

Please sign in to comment.