Skip to content

Commit

Permalink
fix: changed settings are not persisting after force stop #821
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 13, 2023
1 parent 694ddf0 commit e29a38d
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 302 deletions.
3 changes: 2 additions & 1 deletion lib/components/settings/color_scheme_picker_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ColorSchemePickerDialog extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final scheme = preferences.accentColorScheme;
final active = useState<String>(colorsMap.firstWhere(
(element) {
Expand All @@ -57,7 +58,7 @@ class ColorSchemePickerDialog extends HookConsumerWidget {
).name);

onOk() {
preferences.setAccentColorScheme(
preferencesNotifier.setAccentColorScheme(
colorsMap.firstWhere(
(element) {
return element.name == active.value;
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/settings/sections/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SettingsAboutSection extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);

return SectionCardWithHeading(
heading: context.l10n.about,
Expand Down Expand Up @@ -68,7 +69,7 @@ class SettingsAboutSection extends HookConsumerWidget {
secondary: const Icon(SpotubeIcons.update),
title: Text(context.l10n.check_for_updates),
value: preferences.checkUpdate,
onChanged: (checked) => preferences.setCheckUpdate(checked),
onChanged: (checked) => preferencesNotifier.setCheckUpdate(checked),
),
ListTile(
leading: const Icon(SpotubeIcons.info),
Expand Down
9 changes: 5 additions & 4 deletions lib/pages/settings/sections/appearance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SettingsAppearanceSection extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final pickColorScheme = useCallback(() {
return () => showDialog(
context: context,
Expand All @@ -33,7 +34,7 @@ class SettingsAppearanceSection extends HookConsumerWidget {
value: preferences.layoutMode,
onChanged: (value) {
if (value != null) {
preferences.setLayoutMode(value);
preferencesNotifier.setLayoutMode(value);
}
},
options: [
Expand Down Expand Up @@ -71,7 +72,7 @@ class SettingsAppearanceSection extends HookConsumerWidget {
],
onChanged: (value) {
if (value != null) {
preferences.setThemeMode(value);
preferencesNotifier.setThemeMode(value);
}
},
),
Expand All @@ -80,7 +81,7 @@ class SettingsAppearanceSection extends HookConsumerWidget {
title: Text(context.l10n.use_amoled_mode),
subtitle: Text(context.l10n.pitch_dark_theme),
value: preferences.amoledDarkTheme,
onChanged: preferences.setAmoledDarkTheme,
onChanged: preferencesNotifier.setAmoledDarkTheme,
),
ListTile(
leading: const Icon(SpotubeIcons.palette),
Expand All @@ -101,7 +102,7 @@ class SettingsAppearanceSection extends HookConsumerWidget {
title: Text(context.l10n.sync_album_color),
subtitle: Text(context.l10n.sync_album_color_description),
value: preferences.albumColorSync,
onChanged: preferences.setAlbumColorSync,
onChanged: preferencesNotifier.setAlbumColorSync,
),
],
);
Expand Down
7 changes: 4 additions & 3 deletions lib/pages/settings/sections/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SettingsDesktopSection extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);

return SectionCardWithHeading(
heading: context.l10n.desktop,
Expand All @@ -32,21 +33,21 @@ class SettingsDesktopSection extends HookConsumerWidget {
],
onChanged: (value) {
if (value != null) {
preferences.setCloseBehavior(value);
preferencesNotifier.setCloseBehavior(value);
}
},
),
SwitchListTile(
secondary: const Icon(SpotubeIcons.tray),
title: Text(context.l10n.show_tray_icon),
value: preferences.showSystemTrayIcon,
onChanged: preferences.setShowSystemTrayIcon,
onChanged: preferencesNotifier.setShowSystemTrayIcon,
),
SwitchListTile(
secondary: const Icon(SpotubeIcons.window),
title: Text(context.l10n.use_system_title_bar),
value: preferences.systemTitleBar,
onChanged: preferences.setSystemTitleBar,
onChanged: preferencesNotifier.setSystemTitleBar,
),
],
);
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/settings/sections/downloads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SettingsDownloadsSection extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final preferences = ref.watch(userPreferencesProvider);

final pickDownloadLocation = useCallback(() async {
Expand All @@ -22,13 +23,13 @@ class SettingsDownloadsSection extends HookConsumerWidget {
initialDirectory: preferences.downloadLocation,
);
if (dirStr == null) return;
preferences.setDownloadLocation(dirStr);
preferencesNotifier.setDownloadLocation(dirStr);
} else {
String? dirStr = await getDirectoryPath(
initialDirectory: preferences.downloadLocation,
);
if (dirStr == null) return;
preferences.setDownloadLocation(dirStr);
preferencesNotifier.setDownloadLocation(dirStr);
}
}, [preferences.downloadLocation]);

Expand Down
5 changes: 3 additions & 2 deletions lib/pages/settings/sections/language_region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SettingsLanguageRegionSection extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final mediaQuery = MediaQuery.of(context);

return SectionCardWithHeading(
Expand All @@ -26,7 +27,7 @@ class SettingsLanguageRegionSection extends HookConsumerWidget {
value: preferences.locale,
onChanged: (locale) {
if (locale == null) return;
preferences.setLocale(locale);
preferencesNotifier.setLocale(locale);
},
title: Text(context.l10n.language),
secondary: const Icon(SpotubeIcons.language),
Expand Down Expand Up @@ -57,7 +58,7 @@ class SettingsLanguageRegionSection extends HookConsumerWidget {
value: preferences.recommendationMarket,
onChanged: (value) {
if (value == null) return;
preferences.setRecommendationMarket(value);
preferencesNotifier.setRecommendationMarket(value);
},
options: spotifyMarkets
.map(
Expand Down
17 changes: 9 additions & 8 deletions lib/pages/settings/sections/playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final theme = Theme.of(context);

return SectionCardWithHeading(
Expand All @@ -39,7 +40,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
],
onChanged: (value) {
if (value != null) {
preferences.setAudioQuality(value);
preferencesNotifier.setAudioQuality(value);
}
},
),
Expand All @@ -55,7 +56,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
.toList(),
onChanged: (value) {
if (value == null) return;
preferences.setYoutubeApiType(value);
preferencesNotifier.setYoutubeApiType(value);
},
),
AnimatedSwitcher(
Expand Down Expand Up @@ -113,7 +114,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
.toList(),
onChanged: (value) {
if (value != null) {
preferences.setPipedInstance(value);
preferencesNotifier.setPipedInstance(value);
}
},
);
Expand Down Expand Up @@ -141,7 +142,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
.toList(),
onChanged: (value) {
if (value == null) return;
preferences.setSearchMode(value);
preferencesNotifier.setSearchMode(value);
},
),
),
Expand All @@ -155,7 +156,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
title: Text(context.l10n.skip_non_music),
value: preferences.skipNonMusic,
onChanged: (state) {
preferences.setSkipNonMusic(state);
preferencesNotifier.setSkipNonMusic(state);
},
),
),
Expand All @@ -172,7 +173,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
secondary: const Icon(SpotubeIcons.normalize),
title: Text(context.l10n.normalize_audio),
value: preferences.normalizeAudio,
onChanged: preferences.setNormalizeAudio,
onChanged: preferencesNotifier.setNormalizeAudio,
),
AdaptiveSelectTile<MusicCodec>(
secondary: const Icon(SpotubeIcons.stream),
Expand All @@ -190,7 +191,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
.toList(),
onChanged: (value) {
if (value == null) return;
preferences.setStreamMusicCodec(value);
preferencesNotifier.setStreamMusicCodec(value);
},
),
AdaptiveSelectTile<MusicCodec>(
Expand All @@ -209,7 +210,7 @@ class SettingsPlaybackSection extends HookConsumerWidget {
.toList(),
onChanged: (value) {
if (value == null) return;
preferences.setDownloadMusicCodec(value);
preferencesNotifier.setDownloadMusicCodec(value);
},
),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SettingsPage extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {
final preferences = ref.watch(userPreferencesProvider);
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);

return SafeArea(
bottom: false,
Expand Down Expand Up @@ -49,7 +49,7 @@ class SettingsPage extends HookConsumerWidget {
const SettingsAboutSection(),
Center(
child: FilledButton(
onPressed: preferences.reset,
onPressed: preferencesNotifier.reset,
child: Text(context.l10n.restore_defaults),
),
),
Expand Down
Loading

0 comments on commit e29a38d

Please sign in to comment.