Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate from SharedPreferences to CSV based configuration file #36

Merged
merged 4 commits into from
Apr 28, 2024
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
8 changes: 6 additions & 2 deletions lib/helper/command_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:youtube_api/youtube_api.dart';

import '../model/config.dart';

List<String> _defaultData(final Object fromObject, final String command) {
late final String url;
late final String title;
Expand Down Expand Up @@ -89,9 +91,11 @@ Future<void> playFromYoutubeVideo(
await prefs.setStringList('history', historyQueue.toList());
}

final config = await UserConfig.load();

final commands = switch (mode) {
PlayMode.play => prefs.getStringList('video_play_commands'),
PlayMode.listen => prefs.getStringList('video_listen_commands'),
PlayMode.play => config.videoPlayCommand,
PlayMode.listen => config.videoListenCommand,
};

if (commands == null) return;
Expand Down
18 changes: 10 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:youtube_api/youtube_api.dart';

import 'const.dart';
import 'helper/command_parser.dart';
import 'intent.dart';
import 'locale/en_us.dart';
import 'model/config.dart';
import 'model/setting_options.dart';
import 'model/state.dart';
import 'model/theme.dart';
Expand Down Expand Up @@ -39,10 +39,11 @@ class _ThemedAppState extends ConsumerState<ThemedApp> {
void initState() {
WidgetsBinding.instance.addPostFrameCallback((final _) async {
final intialBrightnessMode = ref.read(brightnessModeProvider);
final prefs = await SharedPreferences.getInstance()
.then((final value) => value.getString('theme_brightness'));
if (prefs != null && prefs != intialBrightnessMode.name) {
ref.read(brightnessModeProvider.notifier).switchModeFromString(prefs);
final prefs = await UserConfig.load();
final userBrightness = prefs.theme.brightness;

if (userBrightness != intialBrightnessMode) {
ref.read(brightnessModeProvider.notifier).switchMode(userBrightness);
}
});

Expand Down Expand Up @@ -227,9 +228,10 @@ class _HomePageState extends State<HomePage> {
return;
}

final prefs = await SharedPreferences.getInstance();
final apiKey = prefs.getString('youtube_api_key');
final maxResults = prefs.getInt('youtube_result_per_search');
final prefs = await UserConfig.load();

final apiKey = prefs.youtube?.apiKey;
final maxResults = prefs.youtube?.resultPerSearch;

if (apiKey == null) {
// throw error
Expand Down
Loading
Loading