refactor(omo): deduplicate OMO/OMO Slim via OmoVariant parameterization

Introduce OmoVariant struct with STANDARD/SLIM constants to eliminate
~250 lines of copy-pasted code across DAO, service, commands, and
frontend layers. Adding a new OMO variant now requires only a single
const declaration instead of duplicating ~400 lines.
This commit is contained in:
Jason
2026-02-19 21:11:58 +08:00
parent 8e219b5eb1
commit 1b71dc721c
10 changed files with 493 additions and 741 deletions
+12 -6
View File
@@ -238,22 +238,28 @@ pub async fn set_common_config_snippet(
if app_type == "omo"
&& state
.db
.get_current_omo_provider("opencode")
.get_current_omo_provider("opencode", "omo")
.map_err(|e| e.to_string())?
.is_some()
{
crate::services::OmoService::write_config_to_file(state.inner())
.map_err(|e| e.to_string())?;
crate::services::OmoService::write_config_to_file(
state.inner(),
&crate::services::omo::STANDARD,
)
.map_err(|e| e.to_string())?;
}
if app_type == "omo-slim"
&& state
.db
.get_current_omo_slim_provider("opencode")
.get_current_omo_provider("opencode", "omo-slim")
.map_err(|e| e.to_string())?
.is_some()
{
crate::services::OmoService::write_config_to_file_slim(state.inner())
.map_err(|e| e.to_string())?;
crate::services::OmoService::write_config_to_file(
state.inner(),
&crate::services::omo::SLIM,
)
.map_err(|e| e.to_string())?;
}
Ok(())
}
+9 -9
View File
@@ -1,19 +1,19 @@
use tauri::State;
use crate::services::omo::OmoLocalFileData;
use crate::services::omo::{OmoLocalFileData, SLIM, STANDARD};
use crate::services::OmoService;
use crate::store::AppState;
#[tauri::command]
pub async fn read_omo_local_file() -> Result<OmoLocalFileData, String> {
OmoService::read_local_file().map_err(|e| e.to_string())
OmoService::read_local_file(&STANDARD).map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn get_current_omo_provider_id(state: State<'_, AppState>) -> Result<String, String> {
let provider = state
.db
.get_current_omo_provider("opencode")
.get_current_omo_provider("opencode", "omo")
.map_err(|e| e.to_string())?;
Ok(provider.map(|p| p.id).unwrap_or_default())
}
@@ -28,11 +28,11 @@ pub async fn disable_current_omo(state: State<'_, AppState>) -> Result<(), Strin
if p.category.as_deref() == Some("omo") {
state
.db
.clear_omo_provider_current("opencode", id)
.clear_omo_provider_current("opencode", id, "omo")
.map_err(|e| e.to_string())?;
}
}
OmoService::delete_config_file().map_err(|e| e.to_string())?;
OmoService::delete_config_file(&STANDARD).map_err(|e| e.to_string())?;
Ok(())
}
@@ -53,7 +53,7 @@ pub async fn get_omo_provider_count(state: State<'_, AppState>) -> Result<usize,
#[tauri::command]
pub async fn read_omo_slim_local_file() -> Result<OmoLocalFileData, String> {
OmoService::read_local_file_slim().map_err(|e| e.to_string())
OmoService::read_local_file(&SLIM).map_err(|e| e.to_string())
}
#[tauri::command]
@@ -62,7 +62,7 @@ pub async fn get_current_omo_slim_provider_id(
) -> Result<String, String> {
let provider = state
.db
.get_current_omo_slim_provider("opencode")
.get_current_omo_provider("opencode", "omo-slim")
.map_err(|e| e.to_string())?;
Ok(provider.map(|p| p.id).unwrap_or_default())
}
@@ -77,11 +77,11 @@ pub async fn disable_current_omo_slim(state: State<'_, AppState>) -> Result<(),
if p.category.as_deref() == Some("omo-slim") {
state
.db
.clear_omo_slim_provider_current("opencode", id)
.clear_omo_provider_current("opencode", id, "omo-slim")
.map_err(|e| e.to_string())?;
}
}
OmoService::delete_config_file_slim().map_err(|e| e.to_string())?;
OmoService::delete_config_file(&SLIM).map_err(|e| e.to_string())?;
Ok(())
}