mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-09-19 17:37:29 +02:00
Fix system theme pair integration
This commit is contained in:
@@ -332,7 +332,11 @@ pub fn set_theme(state: State<'_, AppState>, theme: String) -> Result<(), String
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn set_system_themes(state: State<'_, AppState>, light: String, dark: String) -> Result<(), String> {
|
||||
pub fn set_system_themes(
|
||||
state: State<'_, AppState>,
|
||||
light: String,
|
||||
dark: String,
|
||||
) -> Result<(), String> {
|
||||
let mut config = state.config.lock().map_err(|e| e.to_string())?;
|
||||
config.system_light_theme = light;
|
||||
config.system_dark_theme = dark;
|
||||
@@ -363,12 +367,41 @@ pub fn save_custom_theme(state: State<'_, AppState>, theme: crate::types::Custom
|
||||
#[tauri::command]
|
||||
pub fn delete_custom_theme(state: State<'_, AppState>, id: String) -> Result<(), String> {
|
||||
let mut config = state.config.lock().map_err(|e| e.to_string())?;
|
||||
clear_custom_theme_references(&mut config, &id);
|
||||
save_app_config(&config)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_custom_theme_references(config: &mut AppConfig, id: &str) {
|
||||
config.custom_themes.retain(|t| t.id != id);
|
||||
if config.theme == id {
|
||||
config.theme = "system".to_string();
|
||||
}
|
||||
save_app_config(&config)?;
|
||||
Ok(())
|
||||
if config.system_light_theme == id {
|
||||
config.system_light_theme = "light".to_string();
|
||||
}
|
||||
if config.system_dark_theme == id {
|
||||
config.system_dark_theme = "dark".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod custom_theme_reference_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deleting_custom_theme_resets_system_pair_references() {
|
||||
let mut config = AppConfig::default();
|
||||
config.theme = "custom-work".to_string();
|
||||
config.system_light_theme = "custom-work".to_string();
|
||||
config.system_dark_theme = "custom-work".to_string();
|
||||
|
||||
clear_custom_theme_references(&mut config, "custom-work");
|
||||
|
||||
assert_eq!(config.theme, "system");
|
||||
assert_eq!(config.system_light_theme, "light");
|
||||
assert_eq!(config.system_dark_theme, "dark");
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
+14
-1
@@ -505,7 +505,7 @@ pub struct TaskItem {
|
||||
|
||||
#[cfg(test)]
|
||||
mod startup_view_tests {
|
||||
use super::StartupView;
|
||||
use super::{AppConfig, StartupView};
|
||||
|
||||
#[test]
|
||||
fn serializes_supported_startup_views() {
|
||||
@@ -526,4 +526,17 @@ mod startup_view_tests {
|
||||
StartupView::All
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_configs_default_system_theme_pair() {
|
||||
let mut value = serde_json::to_value(AppConfig::default()).unwrap();
|
||||
let object = value.as_object_mut().unwrap();
|
||||
object.remove("system_light_theme");
|
||||
object.remove("system_dark_theme");
|
||||
|
||||
let config: AppConfig = serde_json::from_value(value).unwrap();
|
||||
|
||||
assert_eq!(config.system_light_theme, "light");
|
||||
assert_eq!(config.system_dark_theme, "dark");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user