mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 21:30:17 +08:00
fix: remove last-provider deletion restriction for OMO/OMO Slim plugins
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.
This commit is contained in:
@@ -36,19 +36,6 @@ pub async fn disable_current_omo(state: State<'_, AppState>) -> Result<(), Strin
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_omo_provider_count(state: State<'_, AppState>) -> Result<usize, String> {
|
||||
let providers = state
|
||||
.db
|
||||
.get_all_providers("opencode")
|
||||
.map_err(|e| e.to_string())?;
|
||||
let count = providers
|
||||
.values()
|
||||
.filter(|p| p.category.as_deref() == Some("omo"))
|
||||
.count();
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
// ── OMO Slim commands ───────────────────────────────────────
|
||||
|
||||
#[tauri::command]
|
||||
@@ -84,16 +71,3 @@ pub async fn disable_current_omo_slim(state: State<'_, AppState>) -> Result<(),
|
||||
OmoService::delete_config_file(&SLIM).map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_omo_slim_provider_count(state: State<'_, AppState>) -> Result<usize, String> {
|
||||
let providers = state
|
||||
.db
|
||||
.get_all_providers("opencode")
|
||||
.map_err(|e| e.to_string())?;
|
||||
let count = providers
|
||||
.values()
|
||||
.filter(|p| p.category.as_deref() == Some("omo-slim"))
|
||||
.count();
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
@@ -1035,11 +1035,9 @@ pub fn run() {
|
||||
commands::set_window_theme,
|
||||
commands::read_omo_local_file,
|
||||
commands::get_current_omo_provider_id,
|
||||
commands::get_omo_provider_count,
|
||||
commands::disable_current_omo,
|
||||
commands::read_omo_slim_local_file,
|
||||
commands::get_current_omo_slim_provider_id,
|
||||
commands::get_omo_slim_provider_count,
|
||||
commands::disable_current_omo_slim,
|
||||
// Workspace files (OpenClaw)
|
||||
commands::read_workspace_file,
|
||||
|
||||
@@ -260,18 +260,6 @@ impl ProviderService {
|
||||
state
|
||||
.db
|
||||
.is_omo_provider_current(app_type.as_str(), id, "omo")?;
|
||||
let omo_count = state
|
||||
.db
|
||||
.get_all_providers(app_type.as_str())?
|
||||
.values()
|
||||
.filter(|p| p.category.as_deref() == Some("omo"))
|
||||
.count();
|
||||
|
||||
if omo_count <= 1 && was_current {
|
||||
return Err(AppError::Message(
|
||||
"无法删除当前启用的最后一个 OMO 配置,请先停用".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
state.db.delete_provider(app_type.as_str(), id)?;
|
||||
if was_current {
|
||||
@@ -287,18 +275,6 @@ impl ProviderService {
|
||||
state
|
||||
.db
|
||||
.is_omo_provider_current(app_type.as_str(), id, "omo-slim")?;
|
||||
let slim_count = state
|
||||
.db
|
||||
.get_all_providers(app_type.as_str())?
|
||||
.values()
|
||||
.filter(|p| p.category.as_deref() == Some("omo-slim"))
|
||||
.count();
|
||||
|
||||
if slim_count <= 1 && was_current {
|
||||
return Err(AppError::Message(
|
||||
"无法删除当前启用的最后一个 OMO Slim 配置,请先停用".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
state.db.delete_provider(app_type.as_str(), id)?;
|
||||
if was_current {
|
||||
|
||||
@@ -24,7 +24,6 @@ interface ProviderActionsProps {
|
||||
isTesting?: boolean;
|
||||
isProxyTakeover?: boolean;
|
||||
isOmo?: boolean;
|
||||
isLastOmo?: boolean;
|
||||
onSwitch: () => void;
|
||||
onEdit: () => void;
|
||||
onDuplicate: () => void;
|
||||
@@ -49,7 +48,6 @@ export function ProviderActions({
|
||||
isTesting: _isTesting, // Hidden: stream check feature disabled
|
||||
isProxyTakeover = false,
|
||||
isOmo = false,
|
||||
isLastOmo = false,
|
||||
onSwitch,
|
||||
onEdit,
|
||||
onDuplicate,
|
||||
@@ -192,11 +190,7 @@ export function ProviderActions({
|
||||
|
||||
const buttonState = getMainButtonState();
|
||||
|
||||
const canDelete = isOmo
|
||||
? !(isLastOmo && isCurrent)
|
||||
: isAdditiveMode
|
||||
? true
|
||||
: !isCurrent;
|
||||
const canDelete = isOmo || isAdditiveMode ? true : !isCurrent;
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-1.5">
|
||||
|
||||
@@ -28,9 +28,7 @@ interface ProviderCardProps {
|
||||
appId: AppId;
|
||||
isInConfig?: boolean; // OpenCode: 是否已添加到 opencode.json
|
||||
isOmo?: boolean;
|
||||
isLastOmo?: boolean;
|
||||
isOmoSlim?: boolean;
|
||||
isLastOmoSlim?: boolean;
|
||||
onSwitch: (provider: Provider) => void;
|
||||
onEdit: (provider: Provider) => void;
|
||||
onDelete: (provider: Provider) => void;
|
||||
@@ -94,9 +92,7 @@ export function ProviderCard({
|
||||
appId,
|
||||
isInConfig = true,
|
||||
isOmo = false,
|
||||
isLastOmo = false,
|
||||
isOmoSlim = false,
|
||||
isLastOmoSlim = false,
|
||||
onSwitch,
|
||||
onEdit,
|
||||
onDelete,
|
||||
@@ -125,7 +121,6 @@ export function ProviderCard({
|
||||
|
||||
// OMO and OMO Slim share the same card behavior
|
||||
const isAnyOmo = isOmo || isOmoSlim;
|
||||
const isLastAnyOmo = isOmo ? isLastOmo : isLastOmoSlim;
|
||||
const handleDisableAnyOmo = isOmoSlim ? onDisableOmoSlim : onDisableOmo;
|
||||
|
||||
const { data: health } = useProviderHealth(provider.id, appId);
|
||||
@@ -390,7 +385,6 @@ export function ProviderCard({
|
||||
isTesting={isTesting}
|
||||
isProxyTakeover={isProxyTakeover}
|
||||
isOmo={isAnyOmo}
|
||||
isLastOmo={isLastAnyOmo}
|
||||
onSwitch={() => onSwitch(provider)}
|
||||
onEdit={() => onEdit(provider)}
|
||||
onDuplicate={() => onDuplicate(provider)}
|
||||
|
||||
@@ -36,9 +36,7 @@ import {
|
||||
} from "@/lib/query/failover";
|
||||
import {
|
||||
useCurrentOmoProviderId,
|
||||
useOmoProviderCount,
|
||||
useCurrentOmoSlimProviderId,
|
||||
useOmoSlimProviderCount,
|
||||
} from "@/lib/query/omo";
|
||||
import { useCallback } from "react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -142,9 +140,7 @@ export function ProviderList({
|
||||
|
||||
const isOpenCode = appId === "opencode";
|
||||
const { data: currentOmoId } = useCurrentOmoProviderId(isOpenCode);
|
||||
const { data: omoProviderCount } = useOmoProviderCount(isOpenCode);
|
||||
const { data: currentOmoSlimId } = useCurrentOmoSlimProviderId(isOpenCode);
|
||||
const { data: omoSlimProviderCount } = useOmoSlimProviderCount(isOpenCode);
|
||||
|
||||
const getFailoverPriority = useCallback(
|
||||
(providerId: string): number | undefined => {
|
||||
@@ -293,15 +289,7 @@ export function ProviderList({
|
||||
appId={appId}
|
||||
isInConfig={isProviderInConfig(provider.id)}
|
||||
isOmo={isOmo}
|
||||
isLastOmo={
|
||||
isOmo && (omoProviderCount ?? 0) <= 1 && isOmoCurrent
|
||||
}
|
||||
isOmoSlim={isOmoSlim}
|
||||
isLastOmoSlim={
|
||||
isOmoSlim &&
|
||||
(omoSlimProviderCount ?? 0) <= 1 &&
|
||||
isOmoSlimCurrent
|
||||
}
|
||||
onSwitch={onSwitch}
|
||||
onEdit={onEdit}
|
||||
onDelete={onDelete}
|
||||
@@ -420,9 +408,7 @@ interface SortableProviderCardProps {
|
||||
appId: AppId;
|
||||
isInConfig: boolean;
|
||||
isOmo: boolean;
|
||||
isLastOmo: boolean;
|
||||
isOmoSlim: boolean;
|
||||
isLastOmoSlim: boolean;
|
||||
onSwitch: (provider: Provider) => void;
|
||||
onEdit: (provider: Provider) => void;
|
||||
onDelete: (provider: Provider) => void;
|
||||
@@ -453,9 +439,7 @@ function SortableProviderCard({
|
||||
appId,
|
||||
isInConfig,
|
||||
isOmo,
|
||||
isLastOmo,
|
||||
isOmoSlim,
|
||||
isLastOmoSlim,
|
||||
onSwitch,
|
||||
onEdit,
|
||||
onDelete,
|
||||
@@ -500,9 +484,7 @@ function SortableProviderCard({
|
||||
appId={appId}
|
||||
isInConfig={isInConfig}
|
||||
isOmo={isOmo}
|
||||
isLastOmo={isLastOmo}
|
||||
isOmoSlim={isOmoSlim}
|
||||
isLastOmoSlim={isLastOmoSlim}
|
||||
onSwitch={onSwitch}
|
||||
onEdit={onEdit}
|
||||
onDelete={onDelete}
|
||||
|
||||
@@ -5,7 +5,6 @@ export const omoApi = {
|
||||
readLocalFile: (): Promise<OmoLocalFileData> => invoke("read_omo_local_file"),
|
||||
getCurrentOmoProviderId: (): Promise<string> =>
|
||||
invoke("get_current_omo_provider_id"),
|
||||
getOmoProviderCount: (): Promise<number> => invoke("get_omo_provider_count"),
|
||||
disableCurrentOmo: (): Promise<void> => invoke("disable_current_omo"),
|
||||
};
|
||||
|
||||
@@ -14,7 +13,5 @@ export const omoSlimApi = {
|
||||
invoke("read_omo_slim_local_file"),
|
||||
getCurrentProviderId: (): Promise<string> =>
|
||||
invoke("get_current_omo_slim_provider_id"),
|
||||
getProviderCount: (): Promise<number> =>
|
||||
invoke("get_omo_slim_provider_count"),
|
||||
disableCurrent: (): Promise<void> => invoke("disable_current_omo_slim"),
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@ function createOmoQueryKeys(prefix: string) {
|
||||
return {
|
||||
all: [prefix] as const,
|
||||
currentProviderId: () => [prefix, "current-provider-id"] as const,
|
||||
providerCount: () => [prefix, "provider-count"] as const,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,7 +19,6 @@ function createOmoQueryHooks(
|
||||
function invalidateAll(queryClient: ReturnType<typeof useQueryClient>) {
|
||||
queryClient.invalidateQueries({ queryKey: ["providers"] });
|
||||
queryClient.invalidateQueries({ queryKey: keys.currentProviderId() });
|
||||
queryClient.invalidateQueries({ queryKey: keys.providerCount() });
|
||||
}
|
||||
|
||||
function useCurrentProviderId(enabled = true) {
|
||||
@@ -34,17 +32,6 @@ function createOmoQueryHooks(
|
||||
});
|
||||
}
|
||||
|
||||
function useProviderCount(enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: keys.providerCount(),
|
||||
queryFn:
|
||||
"getOmoProviderCount" in api
|
||||
? (api as typeof omoApi).getOmoProviderCount
|
||||
: (api as typeof omoSlimApi).getProviderCount,
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
function useReadLocalFile() {
|
||||
return useMutation({
|
||||
mutationFn: () => api.readLocalFile(),
|
||||
@@ -65,7 +52,6 @@ function createOmoQueryHooks(
|
||||
return {
|
||||
keys,
|
||||
useCurrentProviderId,
|
||||
useProviderCount,
|
||||
useReadLocalFile,
|
||||
useDisableCurrent,
|
||||
};
|
||||
@@ -82,11 +68,9 @@ export const omoKeys = omoHooks.keys;
|
||||
export const omoSlimKeys = omoSlimHooks.keys;
|
||||
|
||||
export const useCurrentOmoProviderId = omoHooks.useCurrentProviderId;
|
||||
export const useOmoProviderCount = omoHooks.useProviderCount;
|
||||
export const useReadOmoLocalFile = omoHooks.useReadLocalFile;
|
||||
export const useDisableCurrentOmo = omoHooks.useDisableCurrent;
|
||||
|
||||
export const useCurrentOmoSlimProviderId = omoSlimHooks.useCurrentProviderId;
|
||||
export const useOmoSlimProviderCount = omoSlimHooks.useProviderCount;
|
||||
export const useReadOmoSlimLocalFile = omoSlimHooks.useReadLocalFile;
|
||||
export const useDisableCurrentOmoSlim = omoSlimHooks.useDisableCurrent;
|
||||
|
||||
Reference in New Issue
Block a user