mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-06 11:09:28 +00:00
* refactor: consolidate theme definitions by removing separate dark and light theme files * feat: integrate dynamic color support and enhance theme settings management * feat: add theme settings route and update theme management in app settings * feat: enhance theme management by integrating high contrast support in various components * feat: implement mode selection dialog for theme settings and enhance button functionality * refactor: update theme import paths and consolidate theme provider files * feat: enhance theme management by integrating theme selection based on audiobook playback * refactor: update default value for useMaterialThemeFromSystem to false in theme settings * refactor: adjust high contrast condition order in theme settings for consistency * refactor: rename useMaterialThemeOfPlayingItem to useCurrentPlayerThemeThroughoutApp for clarity * refactor: correct spelling in system theme provider and replace with updated implementation * refactor: extract restore backup dialog into a separate widget for improved readability * refactor: reorganize settings sections for clarity and improve restore dialog functionality
73 lines
1.9 KiB
Dart
73 lines
1.9 KiB
Dart
// this provider is used to provide the app settings to the app
|
|
|
|
import 'package:logging/logging.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:vaani/db/available_boxes.dart';
|
|
import 'package:vaani/settings/models/app_settings.dart' as model;
|
|
|
|
part 'app_settings_provider.g.dart';
|
|
|
|
final _box = AvailableHiveBoxes.userPrefsBox;
|
|
|
|
final _logger = Logger('AppSettingsProvider');
|
|
|
|
model.AppSettings loadOrCreateAppSettings() {
|
|
// see if the settings are already in the box
|
|
model.AppSettings? settings;
|
|
if (_box.isNotEmpty) {
|
|
try {
|
|
settings = _box.getAt(0);
|
|
_logger.fine('found settings in box: $settings');
|
|
} catch (e) {
|
|
_logger.warning('error reading settings from box: $e'
|
|
'\nclearing box');
|
|
_box.clear();
|
|
}
|
|
} else {
|
|
_logger.fine('no settings found in box, creating new settings');
|
|
}
|
|
return settings ?? const model.AppSettings();
|
|
}
|
|
|
|
@Riverpod(keepAlive: true)
|
|
class AppSettings extends _$AppSettings {
|
|
@override
|
|
model.AppSettings build() {
|
|
state = loadOrCreateAppSettings();
|
|
ref.listenSelf((_, __) {
|
|
writeToBox();
|
|
});
|
|
return state;
|
|
}
|
|
|
|
// write the settings to the box
|
|
void writeToBox() {
|
|
_box.clear();
|
|
_box.add(state);
|
|
_logger.fine('wrote settings to box: $state');
|
|
}
|
|
|
|
void update(model.AppSettings newSettings) {
|
|
state = newSettings;
|
|
}
|
|
|
|
void reset() {
|
|
state = const model.AppSettings();
|
|
}
|
|
}
|
|
|
|
// SleepTimerSettings provider but only rebuilds when the sleep timer settings change
|
|
@Riverpod(keepAlive: true)
|
|
class SleepTimerSettings extends _$SleepTimerSettings {
|
|
@override
|
|
model.SleepTimerSettings build() {
|
|
final settings = ref.read(appSettingsProvider).sleepTimerSettings;
|
|
state = settings;
|
|
ref.listen(appSettingsProvider, (a, b) {
|
|
if (a?.sleepTimerSettings != b.sleepTimerSettings) {
|
|
state = b.sleepTimerSettings;
|
|
}
|
|
});
|
|
return state;
|
|
}
|
|
}
|