Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Feb 22, 2024
1 parent 576ee7b commit 0c241a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
7 changes: 2 additions & 5 deletions lib/mains/main_netknights.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import 'package:easy_dynamic_theme/easy_dynamic_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:home_widget/home_widget.dart';
import 'package:privacyidea_authenticator/l10n/app_localizations.dart';
import 'package:privacyidea_authenticator/utils/app_customizer.dart';
import 'package:privacyidea_authenticator/utils/globals.dart';
Expand All @@ -46,10 +45,8 @@ void main() async {
navigatorKey: globalNavigatorKey,
appRunner: () async {
WidgetsFlutterBinding.ensureInitialized();
if (HomeWidgetUtils().isSupported) {
await HomeWidget.registerInteractivityCallback(homeWidgetBackgroundCallback);
await HomeWidget.setAppGroupId(appGroupId);
}
await HomeWidgetUtils().registerInteractivityCallback(homeWidgetBackgroundCallback);
await HomeWidgetUtils().setAppGroupId(appGroupId);
runApp(AppWrapper(child: PrivacyIDEAAuthenticator(customization: ApplicationCustomization.defaultCustomization)));
});
}
Expand Down
1 change: 1 addition & 0 deletions lib/utils/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Map<Version, Map<PatchNoteType, List<String>>> getLocalizedPatchNotes(AppLocaliz
final globalSnackbarKey = GlobalKey<ScaffoldMessengerState>();
final globalNavigatorKey = GlobalKey<NavigatorState>();
final Future<GlobalKey<NavigatorState>> contextedGlobalNavigatorKey = Future(() async => await _getContextedGlobalNavigatorKey());
BuildContext? globalContextSync = globalNavigatorKey.currentContext;
final Future<BuildContext> globalContext = Future(() async => await _getContextedGlobalNavigatorKey()).then((value) => value.currentContext!);
Future<GlobalKey<NavigatorState>> _getContextedGlobalNavigatorKey() async {
if (globalNavigatorKey.currentContext != null) {
Expand Down
14 changes: 10 additions & 4 deletions lib/utils/home_widget_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void homeWidgetBackgroundCallback(Uri? uri) async {
}

class HomeWidgetUtils {
bool isSupported = true;
HomeWidgetUtils._();
static HomeWidgetUtils? _instance;

Expand Down Expand Up @@ -197,6 +196,11 @@ class HomeWidgetUtils {
////////////////////////////////////////
/// Note: Prefer to call private methods inside of Public Methods to avoid unnecessary rendering ///
Future<bool?> registerInteractivityCallback(void Function(Uri? uri) homeWidgetBackgroundCallback) =>
HomeWidget.registerInteractivityCallback(homeWidgetBackgroundCallback);

Future<bool?> setAppGroupId(String appGroupId) => HomeWidget.setAppGroupId(appGroupId);

/// This method has to be called at least once before any other method is called
Future<void> homeWidgetInit({TokenRepository? repository}) async {
if (repository != null) _tokenRepository = repository;
Expand Down Expand Up @@ -586,13 +590,11 @@ class HomeWidgetUtils {
Logger.info('Notify Update: $updatedWidgetIds', name: 'home_widget_utils.dart#_notifyUpdate');
_lastUpdate = DateTime.now();
await HomeWidget.saveWidgetData(keyRebuildingWidgetIds, updatedWidgetIds.join(','));
await HomeWidget.updateWidget(qualifiedAndroidName: '${await _packageId}.AppWidgetProvider', iOSName: 'AppWidgetProvider');
await HomeWidget.updateWidget(qualifiedAndroidName: '$_packageId.AppWidgetProvider', iOSName: 'AppWidgetProvider');
}
}

class UnsupportedHomeWidgetUtils implements HomeWidgetUtils {
@override
bool isSupported = false;
@override
DateTime? _lastUpdate;
@override
Expand Down Expand Up @@ -699,4 +701,8 @@ class UnsupportedHomeWidgetUtils implements HomeWidgetUtils {
Future<Uri?> initiallyLaunchedFromHomeWidget() => Future.value(null);
@override
Stream<Uri?> get widgetClicked => const Stream.empty();
@override
Future<bool?> registerInteractivityCallback(void Function(Uri? uri) homeWidgetBackgroundCallback) => Future.value(null);
@override
Future<bool?> setAppGroupId(String appGroupId) => Future.value(null);
}
9 changes: 4 additions & 5 deletions lib/utils/network_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ class PrivacyIdeaIOClient {
try {
await ioClient.post(url, body: '');
} on SocketException {
Logger.error('SocketException', name: 'utils.dart#triggerNetworkAccessPermission');
if (isRetry) {
Logger.warning('SocketException while retrying', name: 'utils.dart#triggerNetworkAccessPermission');
if (globalNavigatorKey.currentState?.context != null) {
globalRef?.read(statusMessageProvider.notifier).state = (
AppLocalizations.of(globalNavigatorKey.currentState!.context)!.connectionFailed,
AppLocalizations.of(globalNavigatorKey.currentState!.context)!.checkYourNetwork,
AppLocalizations.of(await globalContext)!.connectionFailed,
AppLocalizations.of(await globalContext)!.checkYourNetwork,
);
}
ioClient.close();
Expand All @@ -72,8 +71,8 @@ class PrivacyIdeaIOClient {
ioClient.close();
if (globalNavigatorKey.currentState?.context == null) return false;
globalRef?.read(statusMessageProvider.notifier).state = (
AppLocalizations.of(globalNavigatorKey.currentState!.context)!.connectionFailed,
AppLocalizations.of(globalNavigatorKey.currentState!.context)!.checkYourNetwork,
AppLocalizations.of(await globalContext)!.connectionFailed,
AppLocalizations.of(await globalContext)!.checkYourNetwork,
);
return false;
} finally {
Expand Down

0 comments on commit 0c241a5

Please sign in to comment.