mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-07-16 01:17:23 +02:00
refactor: migrate to singleton pattern
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user