mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 00:35:32 +08:00
924f38ebe1
OMO and OMO Slim are OpenCode plugins, not standalone apps — users should be able to fully remove them. Remove the count-based guard that prevented deleting the last active provider, and clean up the now-unused provider-count API surface across the full stack.
74 lines
2.3 KiB
Rust
74 lines
2.3 KiB
Rust
use tauri::State;
|
|
|
|
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(&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", "omo")
|
|
.map_err(|e| e.to_string())?;
|
|
Ok(provider.map(|p| p.id).unwrap_or_default())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn disable_current_omo(state: State<'_, AppState>) -> Result<(), String> {
|
|
let providers = state
|
|
.db
|
|
.get_all_providers("opencode")
|
|
.map_err(|e| e.to_string())?;
|
|
for (id, p) in &providers {
|
|
if p.category.as_deref() == Some("omo") {
|
|
state
|
|
.db
|
|
.clear_omo_provider_current("opencode", id, "omo")
|
|
.map_err(|e| e.to_string())?;
|
|
}
|
|
}
|
|
OmoService::delete_config_file(&STANDARD).map_err(|e| e.to_string())?;
|
|
Ok(())
|
|
}
|
|
|
|
// ── OMO Slim commands ───────────────────────────────────────
|
|
|
|
#[tauri::command]
|
|
pub async fn read_omo_slim_local_file() -> Result<OmoLocalFileData, String> {
|
|
OmoService::read_local_file(&SLIM).map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn get_current_omo_slim_provider_id(
|
|
state: State<'_, AppState>,
|
|
) -> Result<String, String> {
|
|
let provider = state
|
|
.db
|
|
.get_current_omo_provider("opencode", "omo-slim")
|
|
.map_err(|e| e.to_string())?;
|
|
Ok(provider.map(|p| p.id).unwrap_or_default())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn disable_current_omo_slim(state: State<'_, AppState>) -> Result<(), String> {
|
|
let providers = state
|
|
.db
|
|
.get_all_providers("opencode")
|
|
.map_err(|e| e.to_string())?;
|
|
for (id, p) in &providers {
|
|
if p.category.as_deref() == Some("omo-slim") {
|
|
state
|
|
.db
|
|
.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())?;
|
|
Ok(())
|
|
}
|