mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-21 04:40:18 +08:00
fix: enforce OMO ↔ OMO Slim cross-category mutual exclusion
When activating an OMO provider, deactivate all OMO Slim providers in the same transaction and delete the Slim config file, and vice versa. This prevents both plugin variants from being active simultaneously.
This commit is contained in:
@@ -375,6 +375,19 @@ impl Database {
|
||||
params![app_type, category],
|
||||
)
|
||||
.map_err(|e| AppError::Database(e.to_string()))?;
|
||||
// OMO ↔ OMO Slim mutually exclusive: deactivate the opposite category
|
||||
let opposite = match category {
|
||||
"omo" => Some("omo-slim"),
|
||||
"omo-slim" => Some("omo"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(opp) = opposite {
|
||||
tx.execute(
|
||||
"UPDATE providers SET is_current = 0 WHERE app_type = ?1 AND category = ?2",
|
||||
params![app_type, opp],
|
||||
)
|
||||
.map_err(|e| AppError::Database(e.to_string()))?;
|
||||
}
|
||||
let updated = tx
|
||||
.execute(
|
||||
"UPDATE providers SET is_current = 1 WHERE id = ?1 AND app_type = ?2 AND category = ?3",
|
||||
|
||||
@@ -513,6 +513,8 @@ impl ProviderService {
|
||||
state,
|
||||
&crate::services::omo::STANDARD,
|
||||
)?;
|
||||
// OMO ↔ OMO Slim mutually exclusive: remove Slim config
|
||||
let _ = crate::services::OmoService::delete_config_file(&crate::services::omo::SLIM);
|
||||
return Ok(SwitchResult::default());
|
||||
}
|
||||
|
||||
@@ -522,6 +524,10 @@ impl ProviderService {
|
||||
.db
|
||||
.set_omo_provider_current(app_type.as_str(), id, "omo-slim")?;
|
||||
crate::services::OmoService::write_config_to_file(state, &crate::services::omo::SLIM)?;
|
||||
// OMO ↔ OMO Slim mutually exclusive: remove Standard config
|
||||
let _ = crate::services::OmoService::delete_config_file(
|
||||
&crate::services::omo::STANDARD,
|
||||
);
|
||||
return Ok(SwitchResult::default());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user