refactor: migrate to singleton pattern

This commit is contained in:
zhom
2025-08-02 16:29:40 +04:00
parent 57a36a5fc2
commit 2c57920d44
17 changed files with 501 additions and 377 deletions
+12 -3
View File
@@ -9,10 +9,14 @@ pub struct SystemTheme {
pub struct ThemeDetector;
impl ThemeDetector {
pub fn new() -> Self {
fn new() -> Self {
Self
}
pub fn instance() -> &'static ThemeDetector {
&THEME_DETECTOR
}
/// Detect the system theme preference
pub fn detect_system_theme(&self) -> SystemTheme {
#[cfg(target_os = "linux")]
@@ -514,7 +518,7 @@ mod windows {
// Command to expose this functionality to the frontend
#[tauri::command]
pub fn get_system_theme() -> SystemTheme {
let detector = ThemeDetector::new();
let detector = ThemeDetector::instance();
detector.detect_system_theme()
}
@@ -524,7 +528,7 @@ mod tests {
#[test]
fn test_theme_detector_creation() {
let detector = ThemeDetector::new();
let detector = ThemeDetector::instance();
let theme = detector.detect_system_theme();
// Should return a valid theme string
@@ -537,3 +541,8 @@ mod tests {
assert!(matches!(theme.theme.as_str(), "light" | "dark" | "unknown"));
}
}
// Global singleton instance
lazy_static::lazy_static! {
static ref THEME_DETECTOR: ThemeDetector = ThemeDetector::new();
}