add: 增加任务完成的提示音

This commit is contained in:
2026-04-26 13:10:14 +08:00
parent ce10295e89
commit 3c0d98f4cc
20 changed files with 265 additions and 22 deletions

View File

@@ -6,7 +6,7 @@ use crate::app_error::AppCommandError;
use crate::db::service::app_metadata_service;
#[cfg(feature = "tauri-runtime")]
use crate::db::AppDatabase;
use crate::models::{SystemLanguageSettings, SystemProxySettings};
use crate::models::{SystemLanguageSettings, SystemNotificationSettings, SystemProxySettings};
#[cfg(feature = "tauri-runtime")]
use crate::models::SystemRenderingSettings;
#[cfg(feature = "tauri-runtime")]
@@ -16,6 +16,7 @@ use crate::network::proxy;
const SYSTEM_PROXY_SETTINGS_KEY: &str = "system_proxy_settings";
const SYSTEM_LANGUAGE_SETTINGS_KEY: &str = "system_language_settings";
const SYSTEM_NOTIFICATION_SETTINGS_KEY: &str = "system_notification_settings";
#[cfg(feature = "tauri-runtime")]
const LANGUAGE_SETTINGS_UPDATED_EVENT: &str = "app://language-settings-updated";
@@ -174,3 +175,46 @@ pub async fn update_system_rendering_settings(
})?;
Ok(settings)
}
pub(crate) async fn load_system_notification_settings(
conn: &DatabaseConnection,
) -> Result<SystemNotificationSettings, AppCommandError> {
let raw = app_metadata_service::get_value(conn, SYSTEM_NOTIFICATION_SETTINGS_KEY)
.await
.map_err(AppCommandError::from)?;
let Some(raw) = raw else {
return Ok(SystemNotificationSettings::new_enabled());
};
serde_json::from_str::<SystemNotificationSettings>(&raw).map_err(|e| {
AppCommandError::configuration_invalid("Failed to parse stored notification settings")
.with_detail(e.to_string())
})
}
#[cfg(feature = "tauri-runtime")]
#[cfg_attr(feature = "tauri-runtime", tauri::command)]
pub async fn get_system_notification_settings(
db: State<'_, AppDatabase>,
) -> Result<SystemNotificationSettings, AppCommandError> {
load_system_notification_settings(&db.conn).await
}
#[cfg(feature = "tauri-runtime")]
#[cfg_attr(feature = "tauri-runtime", tauri::command)]
pub async fn update_system_notification_settings(
settings: SystemNotificationSettings,
db: State<'_, AppDatabase>,
) -> Result<SystemNotificationSettings, AppCommandError> {
let serialized = serde_json::to_string(&settings).map_err(|e| {
AppCommandError::invalid_input("Failed to serialize notification settings")
.with_detail(e.to_string())
})?;
app_metadata_service::upsert_value(&db.conn, SYSTEM_NOTIFICATION_SETTINGS_KEY, &serialized)
.await
.map_err(AppCommandError::from)?;
Ok(settings)
}

View File

@@ -312,6 +312,8 @@ mod tauri_app {
system_settings::update_system_language_settings,
system_settings::get_system_rendering_settings,
system_settings::update_system_rendering_settings,
system_settings::get_system_notification_settings,
system_settings::update_system_notification_settings,
version_control::detect_git,
version_control::test_git_path,
version_control::get_git_settings,

View File

@@ -21,7 +21,7 @@ pub use message::{
};
pub use system::{
GitCredentials, GitDetectResult, GitHubAccountsSettings, GitHubTokenValidation, GitSettings,
SystemLanguageSettings, SystemProxySettings,
SystemLanguageSettings, SystemNotificationSettings, SystemProxySettings,
};
#[cfg(feature = "tauri-runtime")]
pub use system::SystemRenderingSettings;

View File

@@ -44,6 +44,22 @@ pub struct SystemRenderingSettings {
pub disable_hardware_acceleration: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SystemNotificationSettings {
pub task_completion: bool,
pub sound_enabled: bool,
}
impl SystemNotificationSettings {
pub fn new_enabled() -> Self {
Self {
task_completion: true,
sound_enabled: true,
}
}
}
// --- Version Control ---
/// Explicit credentials for a single git remote operation.