diff --git a/lib/features/common/utils/startup_app.dart b/lib/features/common/utils/startup_app.dart index 4c7e5c9..f5fd822 100644 --- a/lib/features/common/utils/startup_app.dart +++ b/lib/features/common/utils/startup_app.dart @@ -8,6 +8,7 @@ import 'package:universal_platform/universal_platform.dart'; import 'package:window_manager/window_manager.dart'; import '../../pocketbase/service/pocketbase.service.dart'; +import '../../theme/theme/app_theme.dart'; import '../../widgetter/plugin_base.dart'; import '../../widgetter/plugins/stremio/stremio_plugin.dart'; @@ -17,7 +18,7 @@ Future startupApp() async { MediaKit.ensureInitialized(); await AppPocketBaseService.ensureInitialized(); - + await AppTheme().ensureInitialized(); await SelectedProfileService.instance.initialize(); if (UniversalPlatform.isDesktop) { @@ -27,6 +28,7 @@ Future startupApp() async { if (kDebugMode) { PluginRegistry.instance.reset(); } + PluginRegistry.instance.registerPlugin( StremioCatalogPlugin(), ); diff --git a/lib/features/theme/theme/app_theme.dart b/lib/features/theme/theme/app_theme.dart index d4c7572..ee6d5ca 100644 --- a/lib/features/theme/theme/app_theme.dart +++ b/lib/features/theme/theme/app_theme.dart @@ -1,10 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../provider/theme_provider.dart'; import '../utils/color_utils.dart'; class AppTheme { static final AppTheme _instance = AppTheme._internal(); + static const String _primaryColorKey = 'primary_color'; + static const String _isDarkModeKey = 'is_dark_mode'; factory AppTheme() { return _instance; @@ -18,13 +21,33 @@ class AppTheme { ThemeProvider get themeProvider => _themeProvider; ColorUtils get colorUtils => _colorUtils; - void toggleTheme() => _themeProvider.toggleTheme(); + Future ensureInitialized() async { + final prefs = await SharedPreferences.getInstance(); - void setPrimaryColor(Color color) => _themeProvider.setPrimaryColor(color); + final isDarkMode = prefs.getBool(_isDarkModeKey) ?? false; + if (isDarkMode) _themeProvider.toggleTheme(); - void setPrimaryColorFromRGB(int r, int g, int b) { - Color color = _colorUtils.colorFromRGB(r, g, b); + final primaryColorValue = prefs.getInt(_primaryColorKey); + if (primaryColorValue != null) { + _themeProvider.setPrimaryColor(Color(primaryColorValue)); + } + } + + Future toggleTheme() async { + _themeProvider.toggleTheme(); + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool(_isDarkModeKey, _themeProvider.isDarkMode); + } + + Future setPrimaryColor(Color color) async { _themeProvider.setPrimaryColor(color); + final prefs = await SharedPreferences.getInstance(); + await prefs.setInt(_primaryColorKey, color.value); + } + + Future setPrimaryColorFromRGB(int r, int g, int b) async { + Color color = _colorUtils.colorFromRGB(r, g, b); + await setPrimaryColor(color); } ThemeData getCurrentTheme() => _themeProvider.getTheme();