mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-04-16 08:12:42 +08:00
fix: add import button for OpenCode/OpenClaw empty state and remove auto-import on startup
Previously OpenCode and OpenClaw auto-imported providers from live config on app startup, which could confuse users. Now they follow the same pattern as Claude/Codex/Gemini: manual import via the empty state button.
This commit is contained in:
@@ -448,18 +448,7 @@ pub fn run() {
|
|||||||
Err(e) => log::warn!("✗ Failed to read skills migration flag: {e}"),
|
Err(e) => log::warn!("✗ Failed to read skills migration flag: {e}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. OpenCode 供应商导入(累加式模式,需特殊处理)
|
// 2. OMO 配置导入(当数据库中无 OMO provider 时,从本地文件导入)
|
||||||
// OpenCode 与其他应用不同:配置文件中可同时存在多个供应商
|
|
||||||
// 需要遍历 provider 字段下的每个供应商并导入
|
|
||||||
match crate::services::provider::import_opencode_providers_from_live(&app_state) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} OpenCode provider(s) from live config");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No OpenCode providers found to import"),
|
|
||||||
Err(e) => log::warn!("○ Failed to import OpenCode providers: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2.2 OMO 配置导入(当数据库中无 OMO provider 时,从本地文件导入)
|
|
||||||
{
|
{
|
||||||
let has_omo = app_state
|
let has_omo = app_state
|
||||||
.db
|
.db
|
||||||
@@ -510,17 +499,6 @@ pub fn run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.4 OpenClaw 供应商导入(累加式模式,需特殊处理)
|
|
||||||
// OpenClaw 与 OpenCode 类似:配置文件中可同时存在多个供应商
|
|
||||||
// 需要遍历 models.providers 字段下的每个供应商并导入
|
|
||||||
match crate::services::provider::import_openclaw_providers_from_live(&app_state) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} OpenClaw provider(s) from live config");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No OpenClaw providers found to import"),
|
|
||||||
Err(e) => log::warn!("○ Failed to import OpenClaw providers: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 导入 MCP 服务器配置(表空时触发)
|
// 3. 导入 MCP 服务器配置(表空时触发)
|
||||||
if app_state.db.is_mcp_table_empty().unwrap_or(false) {
|
if app_state.db.is_mcp_table_empty().unwrap_or(false) {
|
||||||
log::info!("MCP table empty, importing from live configurations...");
|
log::info!("MCP table empty, importing from live configurations...");
|
||||||
|
|||||||
@@ -179,7 +179,17 @@ export function ProviderList({
|
|||||||
// Import current live config as default provider
|
// Import current live config as default provider
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const importMutation = useMutation({
|
const importMutation = useMutation({
|
||||||
mutationFn: () => providersApi.importDefault(appId),
|
mutationFn: async (): Promise<boolean> => {
|
||||||
|
if (appId === "opencode") {
|
||||||
|
const count = await providersApi.importOpenCodeFromLive();
|
||||||
|
return count > 0;
|
||||||
|
}
|
||||||
|
if (appId === "openclaw") {
|
||||||
|
const count = await providersApi.importOpenClawFromLive();
|
||||||
|
return count > 0;
|
||||||
|
}
|
||||||
|
return providersApi.importDefault(appId);
|
||||||
|
},
|
||||||
onSuccess: (imported) => {
|
onSuccess: (imported) => {
|
||||||
if (imported) {
|
if (imported) {
|
||||||
queryClient.invalidateQueries({ queryKey: ["providers", appId] });
|
queryClient.invalidateQueries({ queryKey: ["providers", appId] });
|
||||||
@@ -245,15 +255,11 @@ export function ProviderList({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only show import button for standard apps (not additive-mode apps like OpenCode/OpenClaw)
|
|
||||||
const showImportButton =
|
|
||||||
appId === "claude" || appId === "codex" || appId === "gemini";
|
|
||||||
|
|
||||||
if (sortedProviders.length === 0) {
|
if (sortedProviders.length === 0) {
|
||||||
return (
|
return (
|
||||||
<ProviderEmptyState
|
<ProviderEmptyState
|
||||||
onCreate={onCreate}
|
onCreate={onCreate}
|
||||||
onImport={showImportButton ? () => importMutation.mutate() : undefined}
|
onImport={() => importMutation.mutate()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,14 @@ export const providersApi = {
|
|||||||
async getOpenClawLiveProviderIds(): Promise<string[]> {
|
async getOpenClawLiveProviderIds(): Promise<string[]> {
|
||||||
return await invoke("get_openclaw_live_provider_ids");
|
return await invoke("get_openclaw_live_provider_ids");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从 OpenClaw live 配置导入供应商到数据库
|
||||||
|
* OpenClaw 特有功能:由于累加模式,用户可能已在 openclaw.json 中配置供应商
|
||||||
|
*/
|
||||||
|
async importOpenClawFromLive(): Promise<number> {
|
||||||
|
return await invoke("import_openclaw_providers_from_live");
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user