Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Aug 7, 2024
1 parent dbc6ae1 commit 295fa2d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
5 changes: 3 additions & 2 deletions lib/model/extensions/enums/introduction_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ extension IntroductionX on Introduction {
state.isUncompleted(Introduction.pollForChallenges) &&
Introduction.dragToken.isConditionFulfilled(ref, state) == false &&
Introduction.addFolder.isConditionFulfilled(ref, state) == false,
Introduction.hidePushTokens => ref.watch(settingsProvider).whenOrNull(data: (data) => data.hidePushTokens) ??
SettingsState.hidePushTokensDefault && state.isCompleted(Introduction.pollForChallenges) && state.isUncompleted(Introduction.hidePushTokens),
Introduction.hidePushTokens => (ref.watch(settingsProvider).whenOrNull(data: (data) => data.hidePushTokens) ?? SettingsState.hidePushTokensDefault) &&
state.isCompleted(Introduction.pollForChallenges) &&
state.isUncompleted(Introduction.hidePushTokens),
Introduction.exportTokens => state.isUncompleted(Introduction.exportTokens),
};

Expand Down
16 changes: 7 additions & 9 deletions lib/utils/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Logger {
return file.readAsString();
}

/*----------- INSTANCE MEMBER & GETTER -----------*/
/*----------- INSTANCE MEMBER & GETTER/SETTER -----------*/
Function? _appRunner;
Widget? _app;
String _lastError = 'No error Message';
Expand All @@ -92,11 +92,9 @@ class Logger {

String get _filename => 'logfile.txt';
String? get _fullPath => _logPath != null ? '$_logPath/$_filename' : null;
bool get _verbose {
// if (globalRef == null) return false;
return false;
// return globalRef!.read(settingsProvider).whenOrNull(data: (data) => data.verboseLogging) ?? SettingsState.verboseLoggingDefault; //TODO: fix it
}
static bool _verboseLogging = false;

static void setVerboseLogging(bool value) => _verboseLogging = value;

bool get logfileHasContent {
if (_fullPath == null) return false;
Expand Down Expand Up @@ -135,7 +133,7 @@ class Logger {
void logInfo(String message, {dynamic stackTrace, String? name, bool verbose = false}) {
String infoString = _convertLogToSingleString(message, stackTrace: stackTrace, name: name, logLevel: LogLevel.INFO);
infoString = _textFilter(infoString);
if (_verbose || verbose) {
if (_verboseLogging || verbose) {
_logToFile(infoString);
}
_print(infoString);
Expand All @@ -147,7 +145,7 @@ class Logger {
void logWarning(String message, {dynamic error, dynamic stackTrace, String? name, bool verbose = false}) {
String warningString = _convertLogToSingleString(message, error: error, stackTrace: stackTrace, name: name, logLevel: LogLevel.WARNING);
warningString = _textFilter(warningString);
if (instance._verbose || verbose) {
if (_verboseLogging || verbose) {
instance._logToFile(warningString);
}
_printWarning(warningString);
Expand All @@ -158,7 +156,7 @@ class Logger {
if (!kDebugMode) return;
String debugString = instance._convertLogToSingleString(
message,
stackTrace: stackTrace ?? (instance._verbose || verbose) ? StackTrace.current : null,
stackTrace: stackTrace ?? (_verboseLogging || verbose) ? StackTrace.current : null,
name: name,
logLevel: LogLevel.DEBUG,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,22 @@ class IntroductionNotifier extends _$IntroductionNotifier {
}

Future<void> complete(Introduction introduction) async {
Logger.info('Completing introduction: $introduction', name: 'introduction_provider.dart#complete');
final newState = (await future).withCompletedIntroduction(introduction);
await _saveToRepo(newState);
state = AsyncValue.data(newState);
Logger.debug('New saved state after completion: ${await future}');
}

Future<void> uncomplete(Introduction introduction) async {
Logger.info('Uncompleting introduction: $introduction', name: 'introduction_provider.dart#uncomplete');
final newState = (await future).withoutCompletedIntroduction(introduction);
await _saveToRepo(newState);
state = AsyncValue.data(newState);
}

Future<void> completeAll() async {
Logger.info('Completing all introductions', name: 'introduction_provider.dart#completeAll');
final newState = (await future).withAllCompleted();
await _saveToRepo(newState);
state = AsyncValue.data(newState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SettingsNotifier extends _$SettingsNotifier {
Future<SettingsState> build({
required SettingsRepository repo,
}) async {
Logger.info('New settings notifier created', name: 'settings_notifier.dart#build');
// Logger.info('New settings notifier created', name: 'settings_notifier.dart#build');
_repo = _repoOverride ?? repo;
final newState = await _loadFromRepo();
return newState;
Expand Down Expand Up @@ -147,9 +147,11 @@ class SettingsNotifier extends _$SettingsNotifier {
return updateState((oldState) => oldState.copyWith(localePreference: locale));
}

Future<SettingsState> setVerboseLogging(bool value) {
Future<SettingsState> setVerboseLogging(bool value) async {
Logger.info('Verbose logging set to $value', name: 'settings_notifier.dart#setVerboseLogging');
return updateState((oldState) => oldState.copyWith(verboseLogging: value));
final updatedState = await updateState((oldState) => oldState.copyWith(verboseLogging: value));
Logger.setVerboseLogging(updatedState.verboseLogging);
return updatedState;
}

Future<SettingsState> toggleVerboseLogging() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ class LicensePushViewButton extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) =>
(ref.watch(settingsProvider).whenOrNull(data: (data) => data.hidePushTokens) ?? SettingsState.hidePushTokensDefault)
? FocusedItemAsOverlay(
isFocused: ref.watch(introductionNotifierProvider).when(
data: (value) => value.isConditionFulfilled(ref, Introduction.hidePushTokens),
error: (Object error, StackTrace stackTrace) => false,
loading: () => false,
),
isFocused:
ref.watch(introductionNotifierProvider).whenOrNull(data: (data) => data.isConditionFulfilled(ref, Introduction.hidePushTokens)) ?? false,
tooltipWhenFocused: AppLocalizations.of(context)!.introHidePushTokens,
onComplete: () => ref.read(introductionNotifierProvider.notifier).complete(Introduction.hidePushTokens),
child: AppBarItem(
Expand Down
1 change: 0 additions & 1 deletion lib/views/splash_screen/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class _SplashScreenState extends ConsumerState<SplashScreen> {
Future.wait(
<Future>[
Future.delayed(_splashScreenDuration),
// ref.read(settingsProvider.future),
ref.read(tokenProvider.notifier).initState,
ref.read(tokenFolderProvider.notifier).initState,
AppInfoUtils.init(),
Expand Down

0 comments on commit 295fa2d

Please sign in to comment.