Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Aug 8, 2024
1 parent 2921c41 commit 16c8e4e
Show file tree
Hide file tree
Showing 61 changed files with 2,388 additions and 1,136 deletions.
4 changes: 2 additions & 2 deletions integration_test/add_tokens_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import 'package:privacyidea_authenticator/utils/riverpod/state_notifiers/token_n
import 'package:privacyidea_authenticator/utils/customization/application_customization.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/introduction_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_folder_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import 'package:privacyidea_authenticator/views/add_token_manually_view/add_token_manually_view.dart';
import 'package:privacyidea_authenticator/views/add_token_manually_view/add_token_manually_view_widgets/labeled_dropdown_button.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/app_bar_item.dart';
Expand Down
4 changes: 2 additions & 2 deletions integration_test/copy_to_clipboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import 'package:privacyidea_authenticator/utils/customization/application_custom
import 'package:privacyidea_authenticator/model/version.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/introduction_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_folder_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';

import '../test/tests_app_wrapper.dart';
import '../test/tests_app_wrapper.mocks.dart';
Expand Down
4 changes: 2 additions & 2 deletions integration_test/rename_and_delete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import 'package:privacyidea_authenticator/utils/customization/application_custom
import 'package:privacyidea_authenticator/model/version.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/introduction_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_folder_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/default_token_actions/default_delete_action.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/hotp_token_widgets/actions/edit_hotp_token_action.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/hotp_token_widgets/hotp_token_widget.dart';
Expand Down
4 changes: 2 additions & 2 deletions integration_test/two_step_rollout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import 'package:privacyidea_authenticator/utils/logger.dart';
import 'package:privacyidea_authenticator/model/version.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/introduction_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_folder_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/hotp_token_widgets/hotp_token_widget_tile.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/totp_token_widgets/totp_token_widget_tile.dart';
Expand Down
4 changes: 2 additions & 2 deletions integration_test/views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import 'package:privacyidea_authenticator/utils/globals.dart';
import 'package:privacyidea_authenticator/utils/push_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/introduction_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_folder_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import 'package:privacyidea_authenticator/utils/rsa_utils.dart';
import 'package:privacyidea_authenticator/model/version.dart';
import 'package:privacyidea_authenticator/views/settings_view/settings_view_widgets/settings_groups.dart';
Expand Down
41 changes: 41 additions & 0 deletions lib/interfaces/riverpod/buildless_listener.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* privacyIDEA Authenticator
*
* Author: Frank Merkel <[email protected]>
*
* Copyright (c) 2024 NetKnights GmbH
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// ignore: invalid_use_of_internal_member
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../../utils/logger.dart';

// ignore: invalid_use_of_internal_member
abstract class BuildlessListener<T extends BuildlessNotifier<S>, S> {
final String listenerName;
// ignore: invalid_use_of_internal_member
final NotifierProviderImpl<T, S> provider;
final void Function(S? previous, S next) onNewState;
const BuildlessListener({required this.provider, required this.onNewState, required this.listenerName});
void buildListen(WidgetRef ref) {
Logger.debug('("$listenerName") listening to provider ("$provider")', name: 'StateNotifierProviderListener#buildListen');
ref.listen(provider, (previous, next) {
WidgetsBinding.instance.addPostFrameCallback((_) => onNewState(previous, next));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../model/riverpod_states/token_state.dart';
import '../../../../utils/riverpod/state_notifiers/token_notifier.dart';
import '../state_notifier_provider_listener.dart';

abstract class TokenStateListener extends StateNotifierProviderListener<TokenNotifier, TokenState> {
import '../../../../utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import '../../buildless_listener.dart';

abstract class TokenStateListener extends BuildlessListener<TokenNotifier, TokenState> {
const TokenStateListener({
required StateNotifierProvider<TokenNotifier, TokenState> tokenProvider,
required super.provider,
required super.onNewState,
required super.listenerName,
}) : super(provider: tokenProvider);
});
}
2 changes: 1 addition & 1 deletion lib/model/extensions/enums/introduction_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:privacyidea_authenticator/model/riverpod_states/settings_state.d

import '../../../l10n/app_localizations.dart';
import '../../../utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import '../../../utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import '../../../utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import '../../enums/introduction.dart';
import '../../riverpod_states/introduction_state.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/model/push_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import 'package:json_annotation/json_annotation.dart';
import '../utils/globals.dart';
import '../utils/identifiers.dart';
import '../utils/logger.dart';
import '../utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import '../utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import '../utils/rsa_utils.dart';
import 'tokens/push_token.dart';

Expand Down
9 changes: 4 additions & 5 deletions lib/model/riverpod_states/token_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ class TokenState {

List<Token> get maybePiTokens => tokens.maybePiTokens;

TokenState({
required List<Token> tokens,
const TokenState({
required this.tokens,
List<Token>? lastlyUpdatedTokens,
List<Token>? lastlyDeletedTokens,
}) : tokens = List<Token>.from(tokens),
lastlyUpdatedTokens = List<Token>.from(lastlyUpdatedTokens ?? tokens),
lastlyDeletedTokens = List<Token>.from(lastlyDeletedTokens ?? []);
}) : lastlyUpdatedTokens = lastlyUpdatedTokens ?? tokens,
lastlyDeletedTokens = lastlyDeletedTokens ?? const [];

List<Token> get tokensNotInContainer {
final tokensNotInContainer = tokens.maybePiTokens.where((token) => token.containerSerial != null).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import 'package:flutter/material.dart';
import '../../../utils/globals.dart';
import '../../../utils/home_widget_utils.dart';
import '../../../utils/logger.dart';
import '../../../utils/riverpod/riverpod_providers/state_notifier_providers/token_folder_provider.dart';
import '../../../utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import '../../../utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import '../../../utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import '../../../views/link_home_widget_view/link_home_widget_view.dart';
import 'navigation_scheme_processor_interface.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/repo/secure_token_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import '../model/tokens/token.dart';
import '../utils/globals.dart';
import '../utils/identifiers.dart';
import '../utils/logger.dart';
import '../utils/riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import '../utils/riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import '../utils/view_utils.dart';
import '../views/settings_view/settings_view_widgets/send_error_dialog.dart';
import '../widgets/dialog_widgets/default_dialog.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/home_widget_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import '../widgets/home_widgets/home_widget_otp.dart';
import '../widgets/home_widgets/home_widget_unlinked.dart';
import 'globals.dart';
import 'logger.dart';
import 'riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import 'riverpod/riverpod_providers/state_providers/home_widget_provider.dart';

const appGroupId = 'group.authenticator_home_widget_group';
Expand Down
4 changes: 1 addition & 3 deletions lib/utils/push_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import 'globals.dart';
import 'logger.dart';
import 'privacyidea_io_client.dart';
import 'riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import 'riverpod/riverpod_providers/state_notifier_providers/token_provider.dart';
import 'riverpod/riverpod_providers/state_notifier_providers/token_notifier.dart';
import 'riverpod/riverpod_providers/state_providers/status_message_provider.dart';
import 'rsa_utils.dart';
import 'utils.dart';
Expand Down Expand Up @@ -301,8 +301,6 @@ class PushProvider {

final connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult.contains(ConnectivityResult.none)) {


if (isManually) {
Logger.info('Tried to poll without any internet connection available.', name: 'push_provider.dart#pollForChallenges');
globalRef?.read(statusMessageProvider.notifier).state = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../../../model/mixins/sortable_mixin.dart';
import '../../../../model/token_folder.dart';
import '../../../../model/tokens/token.dart';
import '../state_notifier_providers/token_folder_provider.dart';
import '../state_notifier_providers/token_provider.dart';
import 'token_folder_notifier.dart';
import '../state_notifier_providers/token_notifier.dart';

part 'sortable_notifier.g.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import '../../../../repo/token_container_state_repositorys/hybrid_token_containe
import '../../../../repo/token_container_state_repositorys/remote_token_container_state_repository.dart';
import '../../../../repo/token_container_state_repositorys/secure_token_container_state_repository.dart.dart';
import '../../../../model/tokens/container_credentials.dart';
import '../state_notifier_providers/token_provider.dart';
import '../state_notifier_providers/token_notifier.dart';

part 'token_container_notifier.g.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import '../../../../model/riverpod_states/token_folder_state.dart';
import '../../../../model/token_folder.dart';
import '../../../logger.dart';

part 'token_folder_provider.g.dart';
part 'token_folder_notifier.g.dart';

final tokenFolderProvider = tokenFolderNotifierProviderOf(repo: PreferenceTokenFolderRepository());

Expand Down Expand Up @@ -75,38 +75,6 @@ class TokenFolderNotifier extends _$TokenFolderNotifier {
return true;
}

// Future<bool> _addOrReplaceFolder(TokenFolder folder) async {
// await _repoMutex.acquire();
// final newState = (state).addOrReplaceFolder(folder);
// final success = await _repo.saveReplaceList(newState.folders);
// if (!success) {
// Logger.warning(
// 'Failed to add or replace folder',
// name: 'TokenFolderNotifier#_addOrReplaceFolder',
// );
// return false;
// }
// // state = newState;
// _repoMutex.release();
// return true;
// }

// Future<bool> _addNewFolder(String name) async {
// await _repoMutex.acquire();
// final newState = (state).addNewFolder(name);
// final success = await _repo.saveReplaceList(newState.folders);
// if (!success) {
// Logger.warning(
// 'Failed to add new folder',
// name: 'TokenFolderNotifier#_addNewFolder',
// );
// return false;
// }
// // state = newState;
// _repoMutex.release();
// return true;
// }

Future<TokenFolderState> addNewFolder(String name) async {
await _stateMutex.acquire();
final oldState = state;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 16c8e4e

Please sign in to comment.