Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/core/app_settings_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:wger/core/consts.dart';
import 'package:wger/core/http_overrides.dart';
import 'package:wger/core/locale.dart';
import 'package:wger/core/logs.dart';
import 'package:wger/core/shared_preferences.dart';
import 'package:wger/l10n/generated/app_localizations.dart';

Expand Down Expand Up @@ -92,6 +93,9 @@ sealed class AppSettings with _$AppSettings {
/// (system wallpaper on Android 12+) instead of the fixed wger seeds.
/// A no-op on platforms without dynamic color support.
@Default(USE_DYNAMIC_COLOR_DEFAULT) bool useDynamicColor,

/// When true, everything is logged instead of only INFO and above.
@Default(VERBOSE_LOGGING_DEFAULT) bool verboseLogging,
}) = _AppSettings;
}

Expand All @@ -113,13 +117,15 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
final keepDataOnLogout = await _loadKeepDataOnLogout();
final allowSelfSignedCerts = await _loadAllowSelfSignedCerts();
final useDynamicColor = await _loadUseDynamicColor();
final verboseLogging = await _loadVerboseLogging();
return AppSettings(
themeMode: themeMode,
userLocale: userLocale,
dashboardItems: items,
keepDataOnLogout: keepDataOnLogout,
allowSelfSignedCerts: allowSelfSignedCerts,
useDynamicColor: useDynamicColor,
verboseLogging: verboseLogging,
);
}

Expand Down Expand Up @@ -238,6 +244,25 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
await _prefs.setBool(PREFS_USE_DYNAMIC_COLOR, value);
}

//
// Verbose logging
//

Future<bool> _loadVerboseLogging() async {
final value = (await _prefs.getBool(PREFS_VERBOSE_LOGGING)) ?? VERBOSE_LOGGING_DEFAULT;
// main() already seeds the level from the same key, applying it here as
// well keeps the two from drifting apart.
applyVerboseLogging(value);
return value;
}

Future<void> setVerboseLogging(bool value) async {
final current = state.asData?.value ?? const AppSettings();
state = AsyncData(current.copyWith(verboseLogging: value));
applyVerboseLogging(value);
await _prefs.setBool(PREFS_VERBOSE_LOGGING, value);
}

//
// Dashboard config
//
Expand Down
41 changes: 23 additions & 18 deletions lib/core/app_settings_notifier.freezed.dart

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

2 changes: 1 addition & 1 deletion lib/core/app_settings_notifier.g.dart

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

6 changes: 6 additions & 0 deletions lib/core/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ const KEEP_DATA_ON_LOGOUT_DEFAULT = true;
const PREFS_ALLOW_SELF_SIGNED_CERTS = 'allowSelfSignedCerts';
const ALLOW_SELF_SIGNED_CERTS_DEFAULT = false;

/// User preference: log everything instead of INFO and above, so a bug report
/// also carries the fine-grained diagnostics. Persisted rather than a session
/// switch, the interesting phase is the one right after a cold start.
const PREFS_VERBOSE_LOGGING = 'verboseLogging';
const VERBOSE_LOGGING_DEFAULT = false;

/// Secure-storage key for the headless refresh token.
const SECURE_STORAGE_REFRESH_TOKEN = 'wger_refresh_token';

Expand Down
54 changes: 34 additions & 20 deletions lib/core/error_dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,38 +347,52 @@ class CopyToClipboardButton extends StatelessWidget {
final logger = Logger('CopyToClipboardButton');
final String text;

CopyToClipboardButton({required this.text, super.key});
/// Renders as an icon button instead of a labelled one, for places where
/// the button sits in a toolbar or is repeated in a list.
final bool iconOnly;

CopyToClipboardButton({required this.text, this.iconOnly = false, super.key});

void _copy(BuildContext context) {
Clipboard.setData(ClipboardData(text: text))
.then((_) {
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Details copied to clipboard!')));
}
})
.catchError((copyError) {
logger.warning('Error copying to clipboard: $copyError');

if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Could not copy details.')));
}
});
}

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);

if (iconOnly) {
return IconButton(
icon: const Icon(Icons.copy_all_outlined),
tooltip: i18n.copyToClipboard,
onPressed: () => _copy(context),
);
}

return TextButton.icon(
icon: const Icon(Icons.copy_all_outlined, size: 18),
label: Text(i18n.copyToClipboard),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
onPressed: () {
Clipboard.setData(ClipboardData(text: text))
.then((_) {
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Details copied to clipboard!')));
}
})
.catchError((copyError) {
logger.warning('Error copying to clipboard: $copyError');

if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Could not copy details.')));
}
});
},
onPressed: () => _copy(context),
);
}
}
Expand Down
Loading